363
return size;
364
}
365
366
+static int run_slot(struct active_request_slot *slot)
367
+{
368
+ int err = 0;
369
+ struct slot_results results;
370
+
371
+ slot->results = &results;
372
+ slot->curl_result = curl_easy_perform(slot->curl);
373
+ finish_active_slot(slot);
374
+
375
+ if (results.curl_result != CURLE_OK) {
376
+ err |= error("RPC failed; result=%d, HTTP code = %ld",
377
+ results.curl_result, results.http_code);
378
+ }
379
+
380
+ return err;
381
+}
382
+
383
+static int probe_rpc(struct rpc_state *rpc)
384
+{
385
+ struct active_request_slot *slot;
386
+ struct curl_slist *headers = NULL;
387
+ struct strbuf buf = STRBUF_INIT;
388
+ int err;
389
+
390
+ slot = get_active_slot();
391
+
392
+ headers = curl_slist_append(headers, rpc->hdr_content_type);
393
+ headers = curl_slist_append(headers, rpc->hdr_accept);
394
+
395
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
396
+ curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
397
+ curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
398
+ curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
399
+ curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
400
+ curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
401
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
402
+ curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
403
+ curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
404
+
405
+ err = run_slot(slot);
406
+
407
+ curl_slist_free_all(headers);
408
+ strbuf_release(&buf);
409
+ return err;
410
+}
411
+
412
static int post_rpc(struct rpc_state *rpc)
413
{
414
struct active_request_slot *slot;
369
- struct slot_results results;
415
struct curl_slist *headers = NULL;
416
int use_gzip = rpc->gzip_request;
417
char *gzip_body = NULL;
373
- int err = 0, large_request = 0;
418
+ int err, large_request = 0;
419
420
/* Try to load the entire request, if we can fit it into the
421
* allocated buffer space we can use HTTP/1.0 and avoid the
438
rpc->len += n;
439
}
440
441
+ if (large_request) {
442
+ err = probe_rpc(rpc);
443
+ if (err)
444
+ return err;
445
+ }
446
+
447
slot = get_active_slot();
397
- slot->results = &results;
448
449
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
450
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
458
/* The request body is large and the size cannot be predicted.
459
* We must use chunked encoding to send it.
460
*/
411
- headers = curl_slist_append(headers, "Expect: 100-continue");
461
+ headers = curl_slist_append(headers, "Expect:");
462
headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
463
rpc->initial_buffer = 1;
464
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
532
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
533
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
534
485
- slot->curl_result = curl_easy_perform(slot->curl);
486
- finish_active_slot(slot);
487
-
488
- if (results.curl_result != CURLE_OK) {
489
- err |= error("RPC failed; result=%d, HTTP code = %ld",
490
- results.curl_result, results.http_code);
491
- }
535
+ err = run_slot(slot);
536
537
curl_slist_free_all(headers);
538
free(gzip_body);