417 Expectation Failed
HTTP response status code 417 Expectation Failed is a client error that is returned by the server to indicate that the conditions set by the client using the Expect header can not be satisfied.
Usage
When the 417 Expectation Failed error message is received, it implies that the client specified one or more conditions for proactive negotiation in the Expect header of the request. This is related to the informational HTTP response 100 Continue.
When a request is submitted using the Expect: 100-continue header, the server will examine relevant details of the request. These might include the Content-Type or Content-Length header fields. If the server is willing to accept the message body then it will return the 100 Continue informational response.
If the server is unwilling to accept the message body then it can send an appropriate status, such as 401 Unauthorized or 405 Method Not Allowed. The 417 Expectation Failed error message is only returned when the server or response chain does not support expectations. Therefore, if this message is received then the client can resend the request without the Expect header.
Note
Search engines like Google will not index a URL with 417 Expectation Failed response status, and consequently, URLs that have been indexed in the past but are now returning this HTTP status code will be removed from the search results.
Special consideration for clients
A client that sends Expect: 100-continue is not required to wait for a specific length of time. Therefore, the client may proceed to transmit the message body without first receiving a response. Moreover, as HTTP/1.0 servers do not support expectations, in case one is being used as an intermediary, the client shall not wait an indefinite period before transmitting the message body.
Special consideration for servers
If a server receives the Expect: 100-continue as part of an HTTP/1.0 request, then it must be ignored. Also, the server does not have to acknowledge with a 100 Continue if the message body has already been received or if instead there is a determination made that there is no message body.
Also, when a server sends a 100 Continue response, it must ultimately send a final status such as 200 OK unless the connection is dropped beforehand.
Finally, if a server responds with the final response in advance of receiving the entire message body, it will indicate in the response what it intends to do in terms of the connection. Specifically, will it close the connection or continue reading and discard the request message.
Example
In the example, the client requests to send a 10K PDF file. The server responds with the 417 Expectation Failed error message because it does not support expectations.
Request
PUT /docs HTTP/1.1
Host: www.example.re
Content-Type: applications/pdf
Content-Length: 10000
Expect: 100-continue
Response
HTTP/1.1 417 Expectation Failed
Content-Type: text/html
Content-Length: 155
<html>
<head>
<title>Expectations not supported</title>
</head>
<body>
<p>We don’t expect much, and neither should you.</p>
</body>
</html>
Code references
.NET
HttpStatusCode.ExpectationFailed
Rust
http::StatusCode::EXPECTATION_FAILED
Rails
:expectation_failed
Go
http.StatusExpectationFailed
Symfony
Response::HTTP_EXPECTATION_FAILED
Python3.5+
http.HTTPStatus.EXPECTATION_FAILED
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_EXPECTATION_FAILED
Angular
@angular/common/http/HttpStatusCode.ExpectationFailed
Takeaway
The 417 Expectation Failed status code is a client error that is sent because the server does not support expectations, yet one was included with the request.