@@ -30,7 +30,6 @@ static CURL *curl_default;
30
30
#endif
31
31
32
32
#define PREV_BUF_SIZE 4096
33
- #define RANGE_HEADER_SIZE 30
34
33
35
34
char curl_errorstr [CURL_ERROR_SIZE ];
36
35
@@ -681,6 +680,7 @@ struct active_request_slot *get_active_slot(void)
681
680
curl_easy_setopt (slot -> curl , CURLOPT_UPLOAD , 0 );
682
681
curl_easy_setopt (slot -> curl , CURLOPT_HTTPGET , 1 );
683
682
curl_easy_setopt (slot -> curl , CURLOPT_FAILONERROR , 1 );
683
+ curl_easy_setopt (slot -> curl , CURLOPT_RANGE , NULL );
684
684
#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
685
685
curl_easy_setopt (slot -> curl , CURLOPT_HTTPAUTH , http_auth_methods );
686
686
#endif
@@ -1173,6 +1173,13 @@ static const char *get_accept_language(void)
1173
1173
return cached_accept_language ;
1174
1174
}
1175
1175
1176
+ static void http_opt_request_remainder (CURL * curl , off_t pos )
1177
+ {
1178
+ char buf [128 ];
1179
+ xsnprintf (buf , sizeof (buf ), "%" PRIuMAX "-" , (uintmax_t )pos );
1180
+ curl_easy_setopt (curl , CURLOPT_RANGE , buf );
1181
+ }
1182
+
1176
1183
/* http_request() targets */
1177
1184
#define HTTP_REQUEST_STRBUF 0
1178
1185
#define HTTP_REQUEST_FILE 1
@@ -1201,11 +1208,8 @@ static int http_request(const char *url,
1201
1208
long posn = ftell (result );
1202
1209
curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION ,
1203
1210
fwrite );
1204
- if (posn > 0 ) {
1205
- strbuf_addf (& buf , "Range: bytes=%ld-" , posn );
1206
- headers = curl_slist_append (headers , buf .buf );
1207
- strbuf_reset (& buf );
1208
- }
1211
+ if (posn > 0 )
1212
+ http_opt_request_remainder (slot -> curl , posn );
1209
1213
} else
1210
1214
curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION ,
1211
1215
fwrite_buffer );
@@ -1515,10 +1519,6 @@ void release_http_pack_request(struct http_pack_request *preq)
1515
1519
fclose (preq -> packfile );
1516
1520
preq -> packfile = NULL ;
1517
1521
}
1518
- if (preq -> range_header != NULL ) {
1519
- curl_slist_free_all (preq -> range_header );
1520
- preq -> range_header = NULL ;
1521
- }
1522
1522
preq -> slot = NULL ;
1523
1523
free (preq -> url );
1524
1524
free (preq );
@@ -1582,7 +1582,6 @@ struct http_pack_request *new_http_pack_request(
1582
1582
struct packed_git * target , const char * base_url )
1583
1583
{
1584
1584
long prev_posn = 0 ;
1585
- char range [RANGE_HEADER_SIZE ];
1586
1585
struct strbuf buf = STRBUF_INIT ;
1587
1586
struct http_pack_request * preq ;
1588
1587
@@ -1620,10 +1619,7 @@ struct http_pack_request *new_http_pack_request(
1620
1619
fprintf (stderr ,
1621
1620
"Resuming fetch of pack %s at byte %ld\n" ,
1622
1621
sha1_to_hex (target -> sha1 ), prev_posn );
1623
- xsnprintf (range , sizeof (range ), "Range: bytes=%ld-" , prev_posn );
1624
- preq -> range_header = curl_slist_append (NULL , range );
1625
- curl_easy_setopt (preq -> slot -> curl , CURLOPT_HTTPHEADER ,
1626
- preq -> range_header );
1622
+ http_opt_request_remainder (preq -> slot -> curl , prev_posn );
1627
1623
}
1628
1624
1629
1625
return preq ;
@@ -1673,8 +1669,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
1673
1669
char prev_buf [PREV_BUF_SIZE ];
1674
1670
ssize_t prev_read = 0 ;
1675
1671
long prev_posn = 0 ;
1676
- char range [RANGE_HEADER_SIZE ];
1677
- struct curl_slist * range_header = NULL ;
1678
1672
struct http_object_request * freq ;
1679
1673
1680
1674
freq = xcalloc (1 , sizeof (* freq ));
@@ -1780,10 +1774,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
1780
1774
fprintf (stderr ,
1781
1775
"Resuming fetch of object %s at byte %ld\n" ,
1782
1776
hex , prev_posn );
1783
- xsnprintf (range , sizeof (range ), "Range: bytes=%ld-" , prev_posn );
1784
- range_header = curl_slist_append (range_header , range );
1785
- curl_easy_setopt (freq -> slot -> curl ,
1786
- CURLOPT_HTTPHEADER , range_header );
1777
+ http_opt_request_remainder (freq -> slot -> curl , prev_posn );
1787
1778
}
1788
1779
1789
1780
return freq ;
0 commit comments