MCPcopy Index your code
hub / github.com/git/git / http_request

Function http_request

http.c:2224–2314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2222#define HTTP_REQUEST_FILE 1
2223
2224static int http_request(const char *url,
2225 void *result, int target,
2226 struct http_get_options *options)
2227{
2228 struct active_request_slot *slot;
2229 struct slot_results results = { .retry_after = -1 };
2230 struct curl_slist *headers = http_copy_default_headers();
2231 struct strbuf buf = STRBUF_INIT;
2232 const char *accept_language;
2233 int ret;
2234
2235 slot = get_active_slot();
2236 curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1L);
2237
2238 if (!result) {
2239 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1L);
2240 } else {
2241 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0L);
2242 curl_easy_setopt(slot->curl, CURLOPT_WRITEDATA, result);
2243
2244 if (target == HTTP_REQUEST_FILE) {
2245 off_t posn = ftello(result);
2246 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,
2247 fwrite);
2248 if (posn > 0)
2249 http_opt_request_remainder(slot->curl, posn);
2250 } else
2251 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,
2252 fwrite_buffer);
2253 }
2254
2255 curl_easy_setopt(slot->curl, CURLOPT_HEADERFUNCTION, fwrite_wwwauth);
2256
2257 accept_language = http_get_accept_language_header();
2258
2259 if (accept_language)
2260 headers = curl_slist_append(headers, accept_language);
2261
2262 strbuf_addstr(&buf, "Pragma:");
2263 if (options->no_cache)
2264 strbuf_addstr(&buf, " no-cache");
2265 if (options->initial_request &&
2266 http_follow_config == HTTP_FOLLOW_INITIAL)
2267 curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1L);
2268
2269 headers = curl_slist_append(headers, buf.buf);
2270
2271 /* Add additional headers here */
2272 if (options->extra_headers) {
2273 const struct string_list_item *item;
2274 for_each_string_list_item(item, options->extra_headers)
2275 headers = curl_slist_append(headers, item->string);
2276 }
2277
2278 headers = http_append_auth_header(&http_auth, headers);
2279
2280 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
2281 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);

Callers 1

http_request_recoverableFunction · 0.85

Calls 10

get_active_slotFunction · 0.85
strbuf_addstrFunction · 0.85
http_append_auth_headerFunction · 0.85
run_one_slotFunction · 0.85
curlinfo_strbufFunction · 0.85
extract_content_typeFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected