@@ -114,6 +114,7 @@ static unsigned long http_auth_methods = CURLAUTH_ANY;
114114
115115static struct curl_slist * pragma_header ;
116116static struct curl_slist * no_pragma_header ;
117+ static struct curl_slist * extra_http_headers ;
117118
118119static struct active_request_slot * active_queue_head ;
119120
@@ -323,6 +324,19 @@ static int http_options(const char *var, const char *value, void *cb)
323324#endif
324325 }
325326
327+ if (!strcmp ("http.extraheader" , var )) {
328+ if (!value ) {
329+ return config_error_nonbool (var );
330+ } else if (!* value ) {
331+ curl_slist_free_all (extra_http_headers );
332+ extra_http_headers = NULL ;
333+ } else {
334+ extra_http_headers =
335+ curl_slist_append (extra_http_headers , value );
336+ }
337+ return 0 ;
338+ }
339+
326340 /* Fall back on the default ones */
327341 return git_default_config (var , value , cb );
328342}
@@ -678,8 +692,10 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
678692 if (remote )
679693 var_override (& http_proxy_authmethod , remote -> http_proxy_authmethod );
680694
681- pragma_header = curl_slist_append (pragma_header , "Pragma: no-cache" );
682- no_pragma_header = curl_slist_append (no_pragma_header , "Pragma:" );
695+ pragma_header = curl_slist_append (http_copy_default_headers (),
696+ "Pragma: no-cache" );
697+ no_pragma_header = curl_slist_append (http_copy_default_headers (),
698+ "Pragma:" );
683699
684700#ifdef USE_CURL_MULTI
685701 {
@@ -765,6 +781,9 @@ void http_cleanup(void)
765781#endif
766782 curl_global_cleanup ();
767783
784+ curl_slist_free_all (extra_http_headers );
785+ extra_http_headers = NULL ;
786+
768787 curl_slist_free_all (pragma_header );
769788 pragma_header = NULL ;
770789
@@ -1163,6 +1182,16 @@ int run_one_slot(struct active_request_slot *slot,
11631182 return handle_curl_result (results );
11641183}
11651184
1185+ struct curl_slist * http_copy_default_headers (void )
1186+ {
1187+ struct curl_slist * headers = NULL , * h ;
1188+
1189+ for (h = extra_http_headers ; h ; h = h -> next )
1190+ headers = curl_slist_append (headers , h -> data );
1191+
1192+ return headers ;
1193+ }
1194+
11661195static CURLcode curlinfo_strbuf (CURL * curl , CURLINFO info , struct strbuf * buf )
11671196{
11681197 char * ptr ;
@@ -1380,7 +1409,7 @@ static int http_request(const char *url,
13801409{
13811410 struct active_request_slot * slot ;
13821411 struct slot_results results ;
1383- struct curl_slist * headers = NULL ;
1412+ struct curl_slist * headers = http_copy_default_headers () ;
13841413 struct strbuf buf = STRBUF_INIT ;
13851414 const char * accept_language ;
13861415 int ret ;
0 commit comments