Skip to content

Commit 25b915d

Browse files
committed
http: add reset and tries for transfer
1 parent 5408115 commit 25b915d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/cdp/domains/fetch.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ fn continueWithAuth(cmd: anytype) !void {
313313
errdefer transfer.abortAuthChallenge();
314314

315315
// restart the request with the provided credentials.
316-
// we need to duplicate the cre
317316
const arena = transfer.arena.allocator();
318317
transfer.updateCredentials(
319318
try std.fmt.allocPrintZ(arena, "{s}:{s}", .{
@@ -322,6 +321,7 @@ fn continueWithAuth(cmd: anytype) !void {
322321
}),
323322
);
324323

324+
transfer.reset();
325325
try bc.cdp.browser.http_client.process(transfer);
326326

327327
if (intercept_state.empty()) {

src/http/Client.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn perform(self: *Client, timeout_ms: c_int) !void {
371371
const transfer = try Transfer.fromEasy(easy);
372372

373373
// In case of auth challenge
374-
if (transfer._auth_challenge != null) {
374+
if (transfer._auth_challenge != null and transfer._tries < 10) { // TODO give a way to configure the number of auth retries.
375375
if (transfer.client.notification) |notification| {
376376
var wait_for_interception = false;
377377
notification.dispatch(.http_request_auth_required, &.{ .transfer = transfer, .wait_for_interception = &wait_for_interception });
@@ -643,6 +643,21 @@ pub const Transfer = struct {
643643
_redirecting: bool = false,
644644
_auth_challenge: ?AuthChallenge = null,
645645

646+
// number of times the transfer has been tried.
647+
// incremented by reset func.
648+
_tries: u8 = 0,
649+
650+
pub fn reset(self: *Transfer) void {
651+
self._redirecting = false;
652+
self._auth_challenge = null;
653+
self._notified_fail = false;
654+
self._header_done_called = false;
655+
self.response_header = null;
656+
self.bytes_received = 0;
657+
658+
self._tries += 1;
659+
}
660+
646661
fn deinit(self: *Transfer) void {
647662
self.req.headers.deinit();
648663
if (self._handle) |handle| {

0 commit comments

Comments
 (0)