Expect
The HTTP Expect request header indicates expectations the client has for the server before sending a request body. The server confirms whether those expectations are met before the client transmits the full content.
Usage
Clients include Expect when sending a large request body through an HTTP PUT or POST request. Before transmitting the full body, the client sends the request headers with the Expect header and waits for the server to respond. The server evaluates the headers and returns 100 Continue if the request is acceptable, signaling the client to proceed with the body.
This mechanism conserves bandwidth. When an HTTP request is destined to fail due to Authentication errors, size limits, or unsupported media types (415), the server rejects the request before the client wastes bandwidth transmitting a potentially large body. The server responds with 417 Expectation Failed or another appropriate error status.
Intermediaries such as proxies forward the Expect header to the origin server. An intermediary unable to meet the expectation returns 417 directly.
The only value defined by the HTTP specification is
100-continue. Servers encountering an unrecognized
expectation value respond with 417.
Values
100-continue
The 100-continue value asks the server to inspect
the request headers and confirm whether the request body
is acceptable. The server responds with 100 Continue
to signal readiness, or with an error status code
to prevent unnecessary data transfer.
Expect: 100-continue
Example
A client uploads a 50 MB file to a server. The client first sends the headers including Expect and the Content-Length to let the server verify the request before the body is transmitted.
PUT /uploads/backup.tar.gz HTTP/1.1
Host: storage.example.re
Content-Type: application/gzip
Content-Length: 52428800
Expect: 100-continue
When the server accepts the expectation, the response signals the client to send the body.
HTTP/1.1 100 Continue
When the server determines the upload exceeds a size limit, the response arrives before any body data crosses the network.
HTTP/1.1 413 Content Too Large
Takeaway
The Expect header with the 100-continue value
enables a two-step handshake before transmitting a
request body. The server confirms readiness with a
100 Continue response or rejects the request early
to save bandwidth.