Skip to content

Commit b793acf

Browse files
peffgitster
authored andcommitted
http: set curl FAILONERROR each time we select a handle
Because we reuse curl handles for multiple requests, the setup of a handle happens in two stages: stable, global setup and per-request setup. The lifecycle of a handle is something like: 1. get_curl_handle; do basic global setup that will last through the whole program (e.g., setting the user agent, ssl options, etc) 2. get_active_slot; set up a per-request baseline (e.g., clearing the read/write functions, making it a GET request, etc) 3. perform the request with curl_*_perform functions 4. goto step 2 to perform another request Breaking it down this way means we can avoid doing global setup from step (1) repeatedly, but we still finish step (2) with a predictable baseline setup that callers can rely on. Until commit 6d052d7 (http: add HTTP_KEEP_ERROR option, 2013-04-05), setting curl's FAILONERROR option was a global setup; we never changed it. However, 6d052d7 introduced an option where some requests might turn off FAILONERROR. Later requests using the same handle would have the option unexpectedly turned off, which meant they would not notice http failures at all. This could easily be seen in the test-suite for the "half-auth" cases of t5541 and t5551. The initial requests turned off FAILONERROR, which meant it was erroneously off for the rpc POST. That worked fine for a successful request, but meant that we failed to react properly to the HTTP 401 (instead, we treated whatever the server handed us as a successful message body). The solution is simple: now that FAILONERROR is a per-request setting, we move it to get_active_slot to make sure it is reset for each request. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4df13f6 commit b793acf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ static CURL *get_curl_handle(void)
282282
#endif
283283
if (ssl_cainfo != NULL)
284284
curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
285-
curl_easy_setopt(result, CURLOPT_FAILONERROR, 1);
286285

287286
if (curl_low_speed_limit > 0 && curl_low_speed_time > 0) {
288287
curl_easy_setopt(result, CURLOPT_LOW_SPEED_LIMIT,
@@ -506,6 +505,7 @@ struct active_request_slot *get_active_slot(void)
506505
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, NULL);
507506
curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
508507
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
508+
curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 1);
509509
if (http_auth.password)
510510
init_curl_http_auth(slot->curl);
511511

0 commit comments

Comments
 (0)