@@ -356,14 +356,59 @@ static size_t rpc_in(const void *ptr, size_t eltsize,
356
356
return size ;
357
357
}
358
358
359
+ static int run_slot (struct active_request_slot * slot )
360
+ {
361
+ int err = 0 ;
362
+ struct slot_results results ;
363
+
364
+ slot -> results = & results ;
365
+ slot -> curl_result = curl_easy_perform (slot -> curl );
366
+ finish_active_slot (slot );
367
+
368
+ if (results .curl_result != CURLE_OK ) {
369
+ err |= error ("RPC failed; result=%d, HTTP code = %ld" ,
370
+ results .curl_result , results .http_code );
371
+ }
372
+
373
+ return err ;
374
+ }
375
+
376
+ static int probe_rpc (struct rpc_state * rpc )
377
+ {
378
+ struct active_request_slot * slot ;
379
+ struct curl_slist * headers = NULL ;
380
+ struct strbuf buf = STRBUF_INIT ;
381
+ int err ;
382
+
383
+ slot = get_active_slot ();
384
+
385
+ headers = curl_slist_append (headers , rpc -> hdr_content_type );
386
+ headers = curl_slist_append (headers , rpc -> hdr_accept );
387
+
388
+ curl_easy_setopt (slot -> curl , CURLOPT_NOBODY , 0 );
389
+ curl_easy_setopt (slot -> curl , CURLOPT_POST , 1 );
390
+ curl_easy_setopt (slot -> curl , CURLOPT_URL , rpc -> service_url );
391
+ curl_easy_setopt (slot -> curl , CURLOPT_ENCODING , "" );
392
+ curl_easy_setopt (slot -> curl , CURLOPT_POSTFIELDS , "0000" );
393
+ curl_easy_setopt (slot -> curl , CURLOPT_POSTFIELDSIZE , 4 );
394
+ curl_easy_setopt (slot -> curl , CURLOPT_HTTPHEADER , headers );
395
+ curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION , fwrite_buffer );
396
+ curl_easy_setopt (slot -> curl , CURLOPT_FILE , & buf );
397
+
398
+ err = run_slot (slot );
399
+
400
+ curl_slist_free_all (headers );
401
+ strbuf_release (& buf );
402
+ return err ;
403
+ }
404
+
359
405
static int post_rpc (struct rpc_state * rpc )
360
406
{
361
407
struct active_request_slot * slot ;
362
- struct slot_results results ;
363
408
struct curl_slist * headers = NULL ;
364
409
int use_gzip = rpc -> gzip_request ;
365
410
char * gzip_body = NULL ;
366
- int err = 0 , large_request = 0 ;
411
+ int err , large_request = 0 ;
367
412
368
413
/* Try to load the entire request, if we can fit it into the
369
414
* allocated buffer space we can use HTTP/1.0 and avoid the
@@ -386,8 +431,13 @@ static int post_rpc(struct rpc_state *rpc)
386
431
rpc -> len += n ;
387
432
}
388
433
434
+ if (large_request ) {
435
+ err = probe_rpc (rpc );
436
+ if (err )
437
+ return err ;
438
+ }
439
+
389
440
slot = get_active_slot ();
390
- slot -> results = & results ;
391
441
392
442
curl_easy_setopt (slot -> curl , CURLOPT_NOBODY , 0 );
393
443
curl_easy_setopt (slot -> curl , CURLOPT_POST , 1 );
@@ -401,7 +451,7 @@ static int post_rpc(struct rpc_state *rpc)
401
451
/* The request body is large and the size cannot be predicted.
402
452
* We must use chunked encoding to send it.
403
453
*/
404
- headers = curl_slist_append (headers , "Expect: 100-continue " );
454
+ headers = curl_slist_append (headers , "Expect:" );
405
455
headers = curl_slist_append (headers , "Transfer-Encoding: chunked" );
406
456
rpc -> initial_buffer = 1 ;
407
457
curl_easy_setopt (slot -> curl , CURLOPT_READFUNCTION , rpc_out );
@@ -475,13 +525,7 @@ static int post_rpc(struct rpc_state *rpc)
475
525
curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION , rpc_in );
476
526
curl_easy_setopt (slot -> curl , CURLOPT_FILE , rpc );
477
527
478
- slot -> curl_result = curl_easy_perform (slot -> curl );
479
- finish_active_slot (slot );
480
-
481
- if (results .curl_result != CURLE_OK ) {
482
- err |= error ("RPC failed; result=%d, HTTP code = %ld" ,
483
- results .curl_result , results .http_code );
484
- }
528
+ err = run_slot (slot );
485
529
486
530
curl_slist_free_all (headers );
487
531
free (gzip_body );
0 commit comments