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 9110: HTTP Semantics §10.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 = #expectation
expectation = token [ "=" ( token / quoted-string ) parameters ]
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
/ "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
/ DIGIT / ALPHA
; any VCHAR, except delimiters
quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
parameters = *( OWS ";" OWS [ parameter ] )
parameter = parameter-name "=" parameter-value
parameter-name = token
parameter-value = ( token / quoted-string )
History
- 1999-06: RFC 2616 §14.20. Expect
- 2014-06: RFC 7231 §5.1.1. Expect. The only recognized value for this header is "100-continue" (case-insensitive), and responding with 417 (Expectation Failed) is now optional (due to lack of widespread support in servers).
- 2022-06: RFC 9110 §10.1.1. Expect. The list of tokens form (similar to RFC 2616) is restored.