836
#define HTTP_REQUEST_STRBUF 0
837
#define HTTP_REQUEST_FILE 1
838
839
-static int http_request(const char *url, struct strbuf *type,
840
- void *result, int target, int options)
839
+static int http_request(const char *url,
840
+ void *result, int target,
841
+ const struct http_get_options *options)
842
{
843
struct active_request_slot *slot;
844
struct slot_results results;
871
}
872
873
strbuf_addstr(&buf, "Pragma:");
873
- if (options & HTTP_NO_CACHE)
874
+ if (options && options->no_cache)
875
strbuf_addstr(&buf, " no-cache");
875
- if (options & HTTP_KEEP_ERROR)
876
+ if (options && options->keep_error)
877
curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
878
879
headers = curl_slist_append(headers, buf.buf);
891
ret = HTTP_START_FAILED;
892
}
893
893
- if (type)
894
- curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, type);
894
+ if (options && options->content_type)
895
+ curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE,
896
+ options->content_type);
897
898
curl_slist_free_all(headers);
899
strbuf_release(&buf);
902
}
903
904
static int http_request_reauth(const char *url,
903
- struct strbuf *type,
905
void *result, int target,
905
- int options)
906
+ struct http_get_options *options)
907
{
907
- int ret = http_request(url, type, result, target, options);
908
+ int ret = http_request(url, result, target, options);
909
if (ret != HTTP_REAUTH)
910
return ret;
911
915
* making our next request. We only know how to do this for
916
* the strbuf case, but that is enough to satisfy current callers.
917
*/
917
- if (options & HTTP_KEEP_ERROR) {
918
+ if (options && options->keep_error) {
919
switch (target) {
920
case HTTP_REQUEST_STRBUF:
921
strbuf_reset(result);
924
die("BUG: HTTP_KEEP_ERROR is only supported with strbufs");
925
}
926
}
926
- return http_request(url, type, result, target, options);
927
+ return http_request(url, result, target, options);
928
}
929
930
int http_get_strbuf(const char *url,
930
- struct strbuf *type,
931
- struct strbuf *result, int options)
931
+ struct strbuf *result,
932
+ struct http_get_options *options)
933
{
933
- return http_request_reauth(url, type, result,
934
- HTTP_REQUEST_STRBUF, options);
934
+ return http_request_reauth(url, result, HTTP_REQUEST_STRBUF, options);
935
}
936
937
/*
940
* If a previous interrupted download is detected (i.e. a previous temporary
941
* file is still around) the download is resumed.
942
*/
943
-static int http_get_file(const char *url, const char *filename, int options)
943
+static int http_get_file(const char *url, const char *filename,
944
+ struct http_get_options *options)
945
{
946
int ret;
947
struct strbuf tmpfile = STRBUF_INIT;
955
goto cleanup;
956
}
957
957
- ret = http_request_reauth(url, NULL, result, HTTP_REQUEST_FILE, options);
958
+ ret = http_request_reauth(url, result, HTTP_REQUEST_FILE, options);
959
fclose(result);
960
961
if (ret == HTTP_OK && move_temp_to_file(tmpfile.buf, filename))
967
968
int http_fetch_ref(const char *base, struct ref *ref)
969
{
970
+ struct http_get_options options = {0};
971
char *url;
972
struct strbuf buffer = STRBUF_INIT;
973
int ret = -1;
974
975
+ options.no_cache = 1;
976
+
977
url = quote_ref_url(base, ref->name);
974
- if (http_get_strbuf(url, NULL, &buffer, HTTP_NO_CACHE) == HTTP_OK) {
978
+ if (http_get_strbuf(url, &buffer, &options) == HTTP_OK) {
979
strbuf_rtrim(&buffer);
980
if (buffer.len == 40)
981
ret = get_sha1_hex(buffer.buf, ref->old_sha1);
1059
1060
int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
1061
{
1062
+ struct http_get_options options = {0};
1063
int ret = 0, i = 0;
1064
char *url, *data;
1065
struct strbuf buf = STRBUF_INIT;
1069
strbuf_addstr(&buf, "objects/info/packs");
1070
url = strbuf_detach(&buf, NULL);
1071
1067
- ret = http_get_strbuf(url, NULL, &buf, HTTP_NO_CACHE);
1072
+ options.no_cache = 1;
1073
+ ret = http_get_strbuf(url, &buf, &options);
1074
if (ret != HTTP_OK)
1075
goto cleanup;
1076