@@ -365,10 +365,21 @@ fn perform(self: *Client, timeout_ms: c_int) !void {
365
365
const easy = msg .easy_handle .? ;
366
366
const transfer = try Transfer .fromEasy (easy );
367
367
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
+
368
372
// release it ASAP so that it's available; some done_callbacks
369
373
// will load more resources.
370
374
self .endTransfer (transfer );
371
375
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
+
372
383
defer transfer .deinit ();
373
384
374
385
if (errorCheck (msg .data .result )) {
@@ -569,7 +580,9 @@ pub const Transfer = struct {
569
580
_handle : ? * Handle = null ,
570
581
571
582
_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 ,
573
586
574
587
fn deinit (self : * Transfer ) void {
575
588
self .req .headers .deinit ();
@@ -668,6 +681,7 @@ pub const Transfer = struct {
668
681
}
669
682
670
683
fn headerCallback (buffer : [* ]const u8 , header_count : usize , buf_len : usize , data : * anyopaque ) callconv (.c ) usize {
684
+ std .debug .print ("HEADER CALLBACK\n " , .{});
671
685
// libcurl should only ever emit 1 header at a time
672
686
std .debug .assert (header_count == 1 );
673
687
@@ -721,6 +735,7 @@ pub const Transfer = struct {
721
735
log .err (.http , "failed to get URL" , .{ .err = err });
722
736
return 0 ;
723
737
};
738
+ std .debug .print ("STATUS {d}\n " , .{status });
724
739
725
740
transfer .response_header = .{
726
741
.url = url ,
@@ -761,6 +776,7 @@ pub const Transfer = struct {
761
776
var wait_for_interception = false ;
762
777
notification .dispatch (.http_request_auth_required , &.{ .transfer = transfer , .wait_for_interception = & wait_for_interception });
763
778
if (wait_for_interception ) {
779
+ transfer ._auth_challenge = true ;
764
780
// The user is send an invitation to intercept this request.
765
781
return buf_len ;
766
782
}
@@ -792,7 +808,7 @@ pub const Transfer = struct {
792
808
return c .CURL_WRITEFUNC_ERROR ;
793
809
};
794
810
795
- if (transfer ._redirecting ) {
811
+ if (transfer ._redirecting or transfer . _auth_challenge ) {
796
812
return chunk_len ;
797
813
}
798
814
0 commit comments