http: add reset and tries for transfer

This commit is contained in:
Pierre Tachoire
2025-08-26 16:44:26 +02:00
parent 4c602256da
commit 520a572bb4
2 changed files with 17 additions and 2 deletions

View File

@@ -313,7 +313,6 @@ fn continueWithAuth(cmd: anytype) !void {
errdefer transfer.abortAuthChallenge();
// restart the request with the provided credentials.
// we need to duplicate the cre
const arena = transfer.arena.allocator();
transfer.updateCredentials(
try std.fmt.allocPrintZ(arena, "{s}:{s}", .{
@@ -322,6 +321,7 @@ fn continueWithAuth(cmd: anytype) !void {
}),
);
transfer.reset();
try bc.cdp.browser.http_client.process(transfer);
if (intercept_state.empty()) {

View File

@@ -371,7 +371,7 @@ fn perform(self: *Client, timeout_ms: c_int) !void {
const transfer = try Transfer.fromEasy(easy);
// In case of auth challenge
if (transfer._auth_challenge != null) {
if (transfer._auth_challenge != null and transfer._tries < 10) { // TODO give a way to configure the number of auth retries.
if (transfer.client.notification) |notification| {
var wait_for_interception = false;
notification.dispatch(.http_request_auth_required, &.{ .transfer = transfer, .wait_for_interception = &wait_for_interception });
@@ -643,6 +643,21 @@ pub const Transfer = struct {
_redirecting: bool = false,
_auth_challenge: ?AuthChallenge = null,
// number of times the transfer has been tried.
// incremented by reset func.
_tries: u8 = 0,
pub fn reset(self: *Transfer) void {
self._redirecting = false;
self._auth_challenge = null;
self._notified_fail = false;
self._header_done_called = false;
self.response_header = null;
self.bytes_received = 0;
self._tries += 1;
}
fn deinit(self: *Transfer) void {
self.req.headers.deinit();
if (self._handle) |handle| {