Where is a delay in an HTTP POST coming from? Where is a delay in an HTTP POST coming from? curl curl

Where is a delay in an HTTP POST coming from?


Problem solved, thanks to debugging and diagnostic techniques suggested by @jxh.

Adding --trace - --trace-time to the curl command revealed that curl was spending that mysterious second waiting for the server to return a 100 Continue response before it sent the rest of the request:

01:31:44.043611 == Info: Connected to localhost (127.0.0.1) port 8787 (#0)01:31:44.043726 => Send header, 175 bytes (0xaf)0000: 50 4f 53 54 20 2f 66 6f 6f 20 48 54 54 50 2f 31 POST /foo HTTP/10010: 2e 31 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 .1..User-Agent: 0020: 63 75 72 6c 2f 37 2e 33 35 2e 30 0d 0a 48 6f 73 curl/7.35.0..Hos0030: 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 38 37 38 t: localhost:8780040: 37 0d 0a 41 63 63 65 70 74 3a 20 2a 2f 2a 0d 0a 7..Accept: */*..0050: 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 Content-Length: 0060: 31 32 30 36 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 1206..Content-Ty0070: 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f pe: application/0080: 78 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c 65 6e x-www-form-urlen0090: 63 6f 64 65 64 0d 0a 45 78 70 65 63 74 3a 20 31 coded..Expect: 100a0: 30 30 2d 63 6f 6e 74 69 6e 75 65 0d 0a 0d 0a    00-continue....01:31:45.045626 == Info: Done waiting for 100-continue01:31:45.045831 => Send data, 1206 bytes (0x4b6)

It is a known deficiency in cpp-netlib (at least as of version 0.11.0) that it does not support sending the 100 Continue response that curl is expecting.

The solution then became convincing curl to not wait for a 100 Continue response. As I discovered here, adding -H 'Expect:' to the curl command line does the trick. With that, the entire transaction takes about a millisecond.

Since I answered my own question, I won't accept my answer for a few weeks to give others a chance to contribute something better.