Skip to content

Commit

Permalink
Merge branch 'bc/http-100-continue'
Browse files Browse the repository at this point in the history
Issue "100 Continue" responses to help use of GSS-Negotiate
authentication scheme over HTTP transport when needed.

* bc/http-100-continue:
  remote-curl: fix large pushes with GSSAPI
  remote-curl: pass curl slot_results back through run_slot
  http: return curl's AUTHAVAIL via slot_results
  • Loading branch information
Junio C Hamano committed Dec 5, 2013
2 parents 07d406b + c80d96c commit c5a77e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
6 changes: 6 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,12 @@ void finish_active_slot(struct active_request_slot *slot)
if (slot->results != NULL) {
slot->results->curl_result = slot->curl_result;
slot->results->http_code = slot->http_code;
#if LIBCURL_VERSION_NUM >= 0x070a08
curl_easy_getinfo(slot->curl, CURLINFO_HTTPAUTH_AVAIL,
&slot->results->auth_avail);
#else
slot->results->auth_avail = 0;
#endif
}

/* Run callback if appropriate */
Expand Down
1 change: 1 addition & 0 deletions http.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
struct slot_results {
CURLcode curl_result;
long http_code;
long auth_avail;
};

struct active_request_slot {
Expand Down
31 changes: 21 additions & 10 deletions remote-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,25 +394,29 @@ static size_t rpc_in(char *ptr, size_t eltsize,
return size;
}

static int run_slot(struct active_request_slot *slot)
static int run_slot(struct active_request_slot *slot,
struct slot_results *results)
{
int err;
struct slot_results results;
struct slot_results results_buf;

slot->results = &results;
if (!results)
results = &results_buf;

slot->results = results;
slot->curl_result = curl_easy_perform(slot->curl);
finish_active_slot(slot);

err = handle_curl_result(&results);
err = handle_curl_result(results);
if (err != HTTP_OK && err != HTTP_REAUTH) {
error("RPC failed; result=%d, HTTP code = %ld",
results.curl_result, results.http_code);
results->curl_result, results->http_code);
}

return err;
}

static int probe_rpc(struct rpc_state *rpc)
static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
{
struct active_request_slot *slot;
struct curl_slist *headers = NULL;
Expand All @@ -434,7 +438,7 @@ static int probe_rpc(struct rpc_state *rpc)
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);

err = run_slot(slot);
err = run_slot(slot, results);

curl_slist_free_all(headers);
strbuf_release(&buf);
Expand All @@ -449,6 +453,7 @@ static int post_rpc(struct rpc_state *rpc)
char *gzip_body = NULL;
size_t gzip_size = 0;
int err, large_request = 0;
int needs_100_continue = 0;

/* Try to load the entire request, if we can fit it into the
* allocated buffer space we can use HTTP/1.0 and avoid the
Expand All @@ -472,18 +477,24 @@ static int post_rpc(struct rpc_state *rpc)
}

if (large_request) {
struct slot_results results;

do {
err = probe_rpc(rpc);
err = probe_rpc(rpc, &results);
if (err == HTTP_REAUTH)
credential_fill(&http_auth);
} while (err == HTTP_REAUTH);
if (err != HTTP_OK)
return -1;

if (results.auth_avail & CURLAUTH_GSSNEGOTIATE)
needs_100_continue = 1;
}

headers = curl_slist_append(headers, rpc->hdr_content_type);
headers = curl_slist_append(headers, rpc->hdr_accept);
headers = curl_slist_append(headers, "Expect:");
headers = curl_slist_append(headers, needs_100_continue ?
"Expect: 100-continue" : "Expect:");

retry:
slot = get_active_slot();
Expand Down Expand Up @@ -574,7 +585,7 @@ static int post_rpc(struct rpc_state *rpc)
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);

err = run_slot(slot);
err = run_slot(slot, NULL);
if (err == HTTP_REAUTH && !large_request) {
credential_fill(&http_auth);
goto retry;
Expand Down

0 comments on commit c5a77e8

Please sign in to comment.