When curl sends 100-continue

When sending a POST request with curl it sometimes automatically adds an Expect: 100-continue header. The following summarizes under which conditions curl/libcurl adds this header.

Background

The Expect: 100-continue header is specified in HTTP 1.1 and allows the server to acknowledge or reject a POST/PUT request immediately after the headers are send but before the client starts sending potentially large amounts of actual data (body of the request). Thus, a conforming client must then wait for a HTTP/1.1 100 Continue before sending the data. This scheme is advantageous for larger POST/PUT requests since in the case of rejection the client and server don't waste their time with superfluous network communication.

Curl Logic

Curl doesn't touch the 'Expect' header if it is explicitly set.

Otherwise, curl automatically sets it, if either

By default, curl waits up to 1 second for a reply to the 100-continue expectation. This timeout is configurable (e.g. via --expect100-timeout SECS).

Disabling Expect Logic

The expect logic can easily be disabled via setting the Expect: header to the empty string.

For example, on the command line via:

$ curl -H 'Expect:' -H 'Transfer-Encoding: ...' -H 'Content-Type: ...' \
    --data-binary '@mediumfile' http://example.org/archive -v

With libcurl the header can be configured via setting CURLOPT_HTTPHEADER using curl_easy_setopt().

Disabling the expect logic saves an additional network round-trip and is thus a good idea when the request isn't extremely large and the probability for rejection is low.

Testing

For testing, the expect logic can also be explicitly turned on, e.g.:

$ curl -H 'Expect: 100-continue' -H 'Content-Type: text/csv+x-lz4' \
    -H 'Transfer-Encoding: chunked' --data-binary ' ' \
    http://example.org/archive -v