Commit 9050c69c0ea4ee5dc8e55ff12736ecd2425c9dc0

Edward Thomson 2019-03-09T17:24:16

http: examine keepalive status at message end We cannot examine the keep-alive status of the http parser in `http_connect`; it's too late and the critical information about whether keep-alive is supported has been destroyed. Per the documentation for `http_should_keep_alive`: > If http_should_keep_alive() in the on_headers_complete or > on_message_complete callback returns 0, then this should be > the last message on the connection. Query then and set the state.

diff --git a/src/transports/http.c b/src/transports/http.c
index bd3f812..453b910 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -108,6 +108,7 @@ typedef struct {
 	int parse_error;
 	int error;
 	unsigned parse_finished : 1,
+	    keepalive : 1,
 	    replay_count : 4;
 } http_subtransport;
 
@@ -571,6 +572,7 @@ static int on_message_complete(http_parser *parser)
 	http_subtransport *t = ctx->t;
 
 	t->parse_finished = 1;
+	t->keepalive = http_should_keep_alive(parser);
 
 	return 0;
 }
@@ -615,6 +617,7 @@ static void clear_parser_state(http_subtransport *t)
 	t->last_cb = NONE;
 	t->parse_error = 0;
 	t->parse_finished = 0;
+	t->keepalive = 0;
 
 	git_buf_dispose(&t->parse_header_name);
 	git_buf_init(&t->parse_header_name, 0);
@@ -929,9 +932,7 @@ static int http_connect(http_subtransport *t)
 	void *cb_payload;
 	int error;
 
-	if (t->connected &&
-		http_should_keep_alive(&t->parser) &&
-		t->parse_finished)
+	if (t->connected && t->keepalive && t->parse_finished)
 		return 0;
 
 	if ((error = load_proxy_config(t)) < 0)