@@ -87,6 +87,7 @@ typedef struct {
8787 char parse_buffer_data [NETIO_BUFSIZE ];
8888 char * content_type ;
8989 char * location ;
90+ git_vector proxy_authenticate ;
9091 git_vector www_authenticate ;
9192 enum last_cb last_cb ;
9293 int parse_error ;
@@ -292,6 +293,12 @@ static int on_header_ready(http_subtransport *t)
292293 GITERR_CHECK_ALLOC (t -> content_type );
293294 }
294295 }
296+ else if (!strcasecmp ("Proxy-Authenticate" , git_buf_cstr (name ))) {
297+ char * dup = git__strdup (git_buf_cstr (value ));
298+ GITERR_CHECK_ALLOC (dup );
299+
300+ git_vector_insert (& t -> proxy_authenticate , dup );
301+ }
295302 else if (!strcasecmp ("WWW-Authenticate" , git_buf_cstr (name ))) {
296303 char * dup = git__strdup (git_buf_cstr (value ));
297304 GITERR_CHECK_ALLOC (dup );
@@ -346,7 +353,14 @@ static int on_header_value(http_parser *parser, const char *str, size_t len)
346353 return 0 ;
347354}
348355
349- static int on_auth_required (http_parser * parser , int allowed_types )
356+ static int on_auth_required (
357+ git_cred * * creds ,
358+ http_parser * parser ,
359+ const char * url ,
360+ git_cred_acquire_cb callback ,
361+ void * callback_payload ,
362+ const char * username ,
363+ int allowed_types )
350364{
351365 parser_context * ctx = (parser_context * ) parser -> data ;
352366 http_subtransport * t = ctx -> t ;
@@ -358,17 +372,13 @@ static int on_auth_required(http_parser *parser, int allowed_types)
358372 return t -> parse_error ;
359373 }
360374
361- if (t -> owner -> cred_acquire_cb ) {
362- if (t -> cred ) {
363- t -> cred -> free (t -> cred );
364- t -> cred = NULL ;
375+ if (callback ) {
376+ if (* creds ) {
377+ ( * creds ) -> free (* creds );
378+ * creds = NULL ;
365379 }
366380
367- ret = t -> owner -> cred_acquire_cb (& t -> cred ,
368- t -> owner -> url ,
369- t -> gitserver_data .user ,
370- allowed_types ,
371- t -> owner -> cred_acquire_payload );
381+ ret = callback (creds , url , username , allowed_types , callback_payload );
372382
373383 if (ret == GIT_PASSTHROUGH ) {
374384 /* treat GIT_PASSTHROUGH as if callback isn't set */
@@ -377,9 +387,9 @@ static int on_auth_required(http_parser *parser, int allowed_types)
377387 t -> parse_error = PARSE_ERROR_EXT ;
378388 return t -> parse_error ;
379389 } else {
380- assert (t -> cred );
390+ assert (* creds );
381391
382- if (!(t -> cred -> credtype & allowed_types )) {
392+ if (!(( * creds ) -> credtype & allowed_types )) {
383393 giterr_set (GITERR_NET , "credential provider returned an invalid cred type" );
384394 t -> parse_error = PARSE_ERROR_GENERIC ;
385395 return t -> parse_error ;
@@ -421,7 +431,13 @@ static int on_headers_complete(http_parser *parser)
421431
422432 /* Check for an authentication failure. */
423433 if (parser -> status_code == 401 && get_verb == s -> verb )
424- return on_auth_required (parser , allowed_www_auth_types );
434+ return on_auth_required (& t -> cred ,
435+ parser ,
436+ t -> owner -> url ,
437+ t -> owner -> cred_acquire_cb ,
438+ t -> owner -> cred_acquire_payload ,
439+ t -> gitserver_data .user ,
440+ allowed_www_auth_types );
425441
426442 /* Check for a redirect.
427443 * Right now we only permit a redirect to the same hostname. */
@@ -554,6 +570,7 @@ static void clear_parser_state(http_subtransport *t)
554570 git__free (t -> location );
555571 t -> location = NULL ;
556572
573+ git_vector_free_deep (& t -> proxy_authenticate );
557574 git_vector_free_deep (& t -> www_authenticate );
558575}
559576
@@ -1076,10 +1093,8 @@ static int http_action(
10761093
10771094 assert (t -> gitserver_data .host && t -> gitserver_data .port && t -> gitserver_data .path );
10781095
1079- if ((ret = load_proxy_config (t )) < 0 )
1080- return ret ;
1081-
1082- if ((ret = http_connect (t )) < 0 )
1096+ if ((ret = load_proxy_config (t )) < 0 ||
1097+ (ret = http_connect (t )) < 0 )
10831098 return ret ;
10841099
10851100 switch (action ) {
0 commit comments