Expect
The "Expect" header field in a request indicates a certain set of behaviors (expectations) that need to be supported by the server in order to properly handle this request.
The only feature that uses this header is 100-continue.
Writing requests (clients)
The Expect header is designed to indicate to the server that the client expects a specific behavior in order to function properly.
In the case of 100-continue
, the client is signaling that it won't begin uploading the request-body until the server signals it is acceptable to do so. Servers that do not support this would send 417, and the client can retry the request without 100-continue.
Reading requests (servers)
If the header exists, and is a value not 100-continue
, return 417 Expectation Failed.
Overview table
- Name
- Expect
- Description
- Lists behaviors expected from the server to properly make the request.
- Direction
- Request
- Specification
- RFC 7231: HTTP/1.1 Semantics and Content ยง5.1.1. Expect
Syntax
Expect = "100-continue"
Example with 100 Continue
The client begins by writing just the headers of the request:
PUT / HTTP/1.1
Host: localhost
Content-Type: text/plain
Content-Length: 10
Expect: 100-continue
The server verifies it can accept an upload of text/plain
of 10 bytes by sending an intermediate status:
HTTP/1.1 100 Continue
The client finishes writing out the body part of the message:
Message!
The server resumes its response message. Note this can still include 1xx intermediate responses.
HTTP/1.1 200 OK
Content-Type: text/plain
Success!
Example with Expectation Failed
The client begins by writing just the headers of the request:
PUT / HTTP/1.1
Host: localhost
Content-Type: text/plain
Content-Length: 10
Expect: 100-continue
A server that does not support 100-continue
will inform the client by writing an error as the final response:
HTTP/1.1 417 Expectation Failed
The client can then retry the upload, making the entire upload and waiting for the server to validate it.
History
RFC7231 removed the "expectation-extension" rule previously defined by RFC2616:
Expect = "Expect" ":" 1#expectation
expectation = "100-continue" / expectation-extension
expectation-extension = token [ "=" ( token / quoted-string ) *expect-params ]
expect-params = ";" token [ "=" ( token / quoted-string ) ]