@@ -582,12 +582,14 @@ pub const Request = struct {
582582};
583583
584584pub const AuthChallenge = struct {
585+ status : u16 ,
585586 source : enum { server , proxy },
586587 scheme : enum { basic , digest },
587588 realm : []const u8 ,
588589
589- pub fn parse (header : []const u8 ) ! AuthChallenge {
590+ pub fn parse (status : u16 , header : []const u8 ) ! AuthChallenge {
590591 var ac : AuthChallenge = .{
592+ .status = status ,
591593 .source = undefined ,
592594 .realm = "TODO" , // TODO parser and set realm
593595 .scheme = undefined ,
@@ -674,7 +676,11 @@ pub const Transfer = struct {
674676 try errorCheck (c .curl_easy_getinfo (easy , c .CURLINFO_EFFECTIVE_URL , & url ));
675677
676678 var status : c_long = undefined ;
677- try errorCheck (c .curl_easy_getinfo (easy , c .CURLINFO_RESPONSE_CODE , & status ));
679+ if (self ._auth_challenge ) | _ | {
680+ status = 407 ;
681+ } else {
682+ try errorCheck (c .curl_easy_getinfo (easy , c .CURLINFO_RESPONSE_CODE , & status ));
683+ }
678684
679685 self .response_header = .{
680686 .url = url ,
@@ -871,6 +877,7 @@ pub const Transfer = struct {
871877 // The auth challenge must be parsed from a following
872878 // WWW-Authenticate or Proxy-Authenticate header.
873879 transfer ._auth_challenge = .{
880+ .status = status ,
874881 .source = undefined ,
875882 .scheme = undefined ,
876883 .realm = undefined ,
@@ -893,7 +900,10 @@ pub const Transfer = struct {
893900 if (std .ascii .startsWithIgnoreCase (header , "WWW-Authenticate" ) or
894901 std .ascii .startsWithIgnoreCase (header , "Proxy-Authenticate" ))
895902 {
896- const ac = AuthChallenge .parse (header ) catch | err | {
903+ const ac = AuthChallenge .parse (
904+ transfer ._auth_challenge .? .status ,
905+ header ,
906+ ) catch | err | {
897907 // We can't parse the auth challenge
898908 log .err (.http , "parse auth challenge" , .{ .err = err , .header = header });
899909 // Should we cancel the request? I don't think so.
0 commit comments