@@ -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
0 commit comments