@@ -824,7 +824,6 @@ GIT_INLINE(int) server_setup_from_url(
824824static void reset_parser (git_http_client * client )
825825{
826826 http_parser_init (& client -> parser , HTTP_RESPONSE );
827- git_buf_clear (& client -> read_buf );
828827}
829828
830829static int setup_hosts (
@@ -869,6 +868,17 @@ GIT_INLINE(int) server_create_stream(git_http_server *server)
869868 return -1 ;
870869}
871870
871+ GIT_INLINE (void ) save_early_response (
872+ git_http_client * client ,
873+ git_http_response * response )
874+ {
875+ /* Buffer the response so we can return it in read_response */
876+ client -> state = HAS_EARLY_RESPONSE ;
877+
878+ memcpy (& client -> early_response , response , sizeof (git_http_response ));
879+ memset (response , 0 , sizeof (git_http_response ));
880+ }
881+
872882static int proxy_connect (
873883 git_http_client * client ,
874884 git_http_request * request )
@@ -905,11 +915,7 @@ static int proxy_connect(
905915 assert (client -> state == DONE );
906916
907917 if (response .status == 407 ) {
908- /* Buffer the response so we can return it in read_response */
909- client -> state = HAS_EARLY_RESPONSE ;
910-
911- memcpy (& client -> early_response , & response , sizeof (response ));
912- memset (& response , 0 , sizeof (response ));
918+ save_early_response (client , & response );
913919
914920 error = GIT_RETRY ;
915921 goto done ;
@@ -1194,6 +1200,7 @@ int git_http_client_send_request(
11941200 git_http_client * client ,
11951201 git_http_request * request )
11961202{
1203+ git_http_response response = {0 };
11971204 int error = -1 ;
11981205
11991206 assert (client && request );
@@ -1220,13 +1227,26 @@ int git_http_client_send_request(
12201227 (error = client_write_request (client )) < 0 )
12211228 goto done ;
12221229
1230+ client -> state = SENT_REQUEST ;
1231+
1232+ if (request -> expect_continue ) {
1233+ if ((error = git_http_client_read_response (& response , client )) < 0 ||
1234+ (error = git_http_client_skip_body (client )) < 0 )
1235+ goto done ;
1236+
1237+ error = 0 ;
1238+
1239+ if (response .status != 100 ) {
1240+ save_early_response (client , & response );
1241+ goto done ;
1242+ }
1243+ }
1244+
12231245 if (request -> content_length || request -> chunked ) {
12241246 client -> state = SENDING_BODY ;
12251247 client -> request_body_len = request -> content_length ;
12261248 client -> request_body_remain = request -> content_length ;
12271249 client -> request_chunked = request -> chunked ;
1228- } else {
1229- client -> state = SENT_REQUEST ;
12301250 }
12311251
12321252 reset_parser (client );
@@ -1235,9 +1255,16 @@ int git_http_client_send_request(
12351255 if (error == GIT_RETRY )
12361256 error = 0 ;
12371257
1258+ git_http_response_dispose (& response );
12381259 return error ;
12391260}
12401261
1262+ bool git_http_client_has_response (git_http_client * client )
1263+ {
1264+ return (client -> state == HAS_EARLY_RESPONSE ||
1265+ client -> state > SENT_REQUEST );
1266+ }
1267+
12411268int git_http_client_send_body (
12421269 git_http_client * client ,
12431270 const char * buffer ,
0 commit comments