Skip to content

Commit 96950fa

Browse files
committed
wip
1 parent a49120e commit 96950fa

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,21 @@ fn perform(self: *Client, timeout_ms: c_int) !void {
365365
const easy = msg.easy_handle.?;
366366
const transfer = try Transfer.fromEasy(easy);
367367

368+
var code: c_long = undefined;
369+
try errorCheck(c.curl_easy_getinfo(easy, c.CURLINFO_RESPONSE_CODE, &code));
370+
std.debug.print("FAILED REQ: {any}\n", .{code});
371+
368372
// release it ASAP so that it's available; some done_callbacks
369373
// will load more resources.
370374
self.endTransfer(transfer);
371375

376+
// If the transfer is waiting for auth challenge interception, don't
377+
// deinit the transfer and don't call the callbacks. All will be done
378+
// later during the interception's response.
379+
if (transfer._auth_challenge) {
380+
continue;
381+
}
382+
372383
defer transfer.deinit();
373384

374385
if (errorCheck(msg.data.result)) {
@@ -569,7 +580,9 @@ pub const Transfer = struct {
569580
_handle: ?*Handle = null,
570581

571582
_redirecting: bool = false,
572-
_forbidden: bool = false,
583+
// True when a request returns a 401 or 407 and we wait for a request
584+
// interception to continue with auth.
585+
_auth_challenge: bool = false,
573586

574587
fn deinit(self: *Transfer) void {
575588
self.req.headers.deinit();
@@ -668,6 +681,7 @@ pub const Transfer = struct {
668681
}
669682

670683
fn headerCallback(buffer: [*]const u8, header_count: usize, buf_len: usize, data: *anyopaque) callconv(.c) usize {
684+
std.debug.print("HEADER CALLBACK\n", .{});
671685
// libcurl should only ever emit 1 header at a time
672686
std.debug.assert(header_count == 1);
673687

@@ -721,6 +735,7 @@ pub const Transfer = struct {
721735
log.err(.http, "failed to get URL", .{ .err = err });
722736
return 0;
723737
};
738+
std.debug.print("STATUS {d}\n", .{status});
724739

725740
transfer.response_header = .{
726741
.url = url,
@@ -761,6 +776,7 @@ pub const Transfer = struct {
761776
var wait_for_interception = false;
762777
notification.dispatch(.http_request_auth_required, &.{ .transfer = transfer, .wait_for_interception = &wait_for_interception });
763778
if (wait_for_interception) {
779+
transfer._auth_challenge = true;
764780
// The user is send an invitation to intercept this request.
765781
return buf_len;
766782
}
@@ -792,7 +808,7 @@ pub const Transfer = struct {
792808
return c.CURL_WRITEFUNC_ERROR;
793809
};
794810

795-
if (transfer._redirecting) {
811+
if (transfer._redirecting or transfer._auth_challenge) {
796812
return chunk_len;
797813
}
798814

src/http/Http.zig

Lines changed: 2 additions & 2 deletions
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

@@ -114,7 +114,7 @@ pub const Connection = struct {
114114
// proxy
115115
if (opts.http_proxy) |proxy| {
116116
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_PROXY, proxy.ptr));
117-
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SUPPRESS_CONNECT_HEADERS, @as(c_long, 1)));
117+
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SUPPRESS_CONNECT_HEADERS, @as(c_long, 0)));
118118
}
119119

120120
// tls

0 commit comments

Comments
 (0)