@@ -291,6 +291,19 @@ static int show_http_message(struct strbuf *type, struct strbuf *charset,
291
291
return 0 ;
292
292
}
293
293
294
+ static int get_protocol_http_header (enum protocol_version version ,
295
+ struct strbuf * header )
296
+ {
297
+ if (version > 0 ) {
298
+ strbuf_addf (header , GIT_PROTOCOL_HEADER ": version=%d" ,
299
+ version );
300
+
301
+ return 1 ;
302
+ }
303
+
304
+ return 0 ;
305
+ }
306
+
294
307
static struct discovery * discover_refs (const char * service , int for_push )
295
308
{
296
309
struct strbuf exp = STRBUF_INIT ;
@@ -299,6 +312,8 @@ static struct discovery *discover_refs(const char *service, int for_push)
299
312
struct strbuf buffer = STRBUF_INIT ;
300
313
struct strbuf refs_url = STRBUF_INIT ;
301
314
struct strbuf effective_url = STRBUF_INIT ;
315
+ struct strbuf protocol_header = STRBUF_INIT ;
316
+ struct string_list extra_headers = STRING_LIST_INIT_DUP ;
302
317
struct discovery * last = last_discovery ;
303
318
int http_ret , maybe_smart = 0 ;
304
319
struct http_get_options http_options ;
@@ -318,11 +333,16 @@ static struct discovery *discover_refs(const char *service, int for_push)
318
333
strbuf_addf (& refs_url , "service=%s" , service );
319
334
}
320
335
336
+ /* Add the extra Git-Protocol header */
337
+ if (get_protocol_http_header (get_protocol_version_config (), & protocol_header ))
338
+ string_list_append (& extra_headers , protocol_header .buf );
339
+
321
340
memset (& http_options , 0 , sizeof (http_options ));
322
341
http_options .content_type = & type ;
323
342
http_options .charset = & charset ;
324
343
http_options .effective_url = & effective_url ;
325
344
http_options .base_url = & url ;
345
+ http_options .extra_headers = & extra_headers ;
326
346
http_options .initial_request = 1 ;
327
347
http_options .no_cache = 1 ;
328
348
http_options .keep_error = 1 ;
@@ -389,6 +409,8 @@ static struct discovery *discover_refs(const char *service, int for_push)
389
409
strbuf_release (& charset );
390
410
strbuf_release (& effective_url );
391
411
strbuf_release (& buffer );
412
+ strbuf_release (& protocol_header );
413
+ string_list_clear (& extra_headers , 0 );
392
414
last_discovery = last ;
393
415
return last ;
394
416
}
@@ -425,6 +447,7 @@ struct rpc_state {
425
447
char * service_url ;
426
448
char * hdr_content_type ;
427
449
char * hdr_accept ;
450
+ char * protocol_header ;
428
451
char * buf ;
429
452
size_t alloc ;
430
453
size_t len ;
@@ -611,6 +634,10 @@ static int post_rpc(struct rpc_state *rpc)
611
634
headers = curl_slist_append (headers , needs_100_continue ?
612
635
"Expect: 100-continue" : "Expect:" );
613
636
637
+ /* Add the extra Git-Protocol header */
638
+ if (rpc -> protocol_header )
639
+ headers = curl_slist_append (headers , rpc -> protocol_header );
640
+
614
641
retry :
615
642
slot = get_active_slot ();
616
643
@@ -751,6 +778,11 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
751
778
strbuf_addf (& buf , "Accept: application/x-%s-result" , svc );
752
779
rpc -> hdr_accept = strbuf_detach (& buf , NULL );
753
780
781
+ if (get_protocol_http_header (heads -> version , & buf ))
782
+ rpc -> protocol_header = strbuf_detach (& buf , NULL );
783
+ else
784
+ rpc -> protocol_header = NULL ;
785
+
754
786
while (!err ) {
755
787
int n = packet_read (rpc -> out , NULL , NULL , rpc -> buf , rpc -> alloc , 0 );
756
788
if (!n )
@@ -778,6 +810,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
778
810
free (rpc -> service_url );
779
811
free (rpc -> hdr_content_type );
780
812
free (rpc -> hdr_accept );
813
+ free (rpc -> protocol_header );
781
814
free (rpc -> buf );
782
815
strbuf_release (& buf );
783
816
return err ;
0 commit comments