Skip to content

Commit fe3b9c2

Browse files
committed
wip
1 parent 6304cf2 commit fe3b9c2

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/cdp/cdp.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ pub fn BrowserContext(comptime CDP_T: type) type {
477477
self.cdp.browser.notification.unregister(.http_response_header_done, self);
478478
}
479479

480-
pub fn fetchEnable(self: *Self, auth: bool) !void {
480+
pub fn fetchEnable(self: *Self, authRequests: bool) !void {
481481
try self.cdp.browser.notification.register(.http_request_intercept, self, onHttpRequestIntercept);
482-
if (auth) {
482+
if (authRequests) {
483483
try self.cdp.browser.notification.register(.http_request_auth_required, self, onHttpRequestAuthRequired);
484484
}
485485
}

src/cdp/domains/fetch.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ const AuthChallenge = struct {
371371
};
372372

373373
pub fn requestAuthRequired(arena: Allocator, bc: anytype, intercept: *const Notification.RequestAuthRequired) !void {
374+
std.log.debug("AUTH REQU FETCH\n", .{});
374375
// unreachable because we _have_ to have a page.
375376
const session_id = bc.session_id orelse unreachable;
376377
const target_id = bc.target_id orelse unreachable;

src/http/Client.zig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,21 @@ fn perform(self: *Client, timeout_ms: c_int) !void {
372372
const easy = msg.easy_handle.?;
373373
const transfer = try Transfer.fromEasy(easy);
374374

375+
var code: c_long = undefined;
376+
try errorCheck(c.curl_easy_getinfo(easy, c.CURLINFO_RESPONSE_CODE, &code));
377+
std.debug.print("FAILED REQ: {any}\n", .{code});
378+
375379
// release it ASAP so that it's available; some done_callbacks
376380
// will load more resources.
377381
self.endTransfer(transfer);
378382

383+
// If the transfer is waiting for auth challenge interception, don't
384+
// deinit the transfer and don't call the callbacks. All will be done
385+
// later during the interception's response.
386+
if (transfer._auth_challenge) {
387+
continue;
388+
}
389+
379390
defer transfer.deinit();
380391

381392
if (errorCheck(msg.data.result)) {
@@ -577,7 +588,9 @@ pub const Transfer = struct {
577588
_handle: ?*Handle = null,
578589

579590
_redirecting: bool = false,
580-
_forbidden: bool = false,
591+
// True when a request returns a 401 or 407 and we wait for a request
592+
// interception to continue with auth.
593+
_auth_challenge: bool = false,
581594

582595
// use_proxy is set when the transfer has been associated to a given
583596
// connection in makeRequest().
@@ -807,6 +820,7 @@ pub const Transfer = struct {
807820
var wait_for_interception = false;
808821
notification.dispatch(.http_request_auth_required, &.{ .transfer = transfer, .wait_for_interception = &wait_for_interception });
809822
if (wait_for_interception) {
823+
transfer._auth_challenge = true;
810824
// The user is send an invitation to intercept this request.
811825
return buf_len;
812826
}
@@ -841,7 +855,7 @@ pub const Transfer = struct {
841855
return c.CURL_WRITEFUNC_ERROR;
842856
};
843857

844-
if (transfer._redirecting) {
858+
if (transfer._redirecting or transfer._auth_challenge) {
845859
return chunk_len;
846860
}
847861

src/http/Http.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub const c = @cImport({
2222
@cInclude("curl/curl.h");
2323
});
2424

25-
pub const ENABLE_DEBUG = false;
25+
pub const ENABLE_DEBUG = true;
2626
pub const Client = @import("Client.zig");
2727
pub const Transfer = Client.Transfer;
2828

0 commit comments

Comments
 (0)