417 Expectation Failed
Usage
When the 417 Expectation Failed error message is received, the client specified one or more conditions for proactive negotiation in the Expect header of the request. This is related to the informational 100 response.
When a request is submitted using the Expect: 100-continue header, the server examines relevant details of the request. These include the Content-Type or Content-Length header fields. If the server is willing to accept the message body, the 100 informational response is returned.
If the server is unwilling to accept the message body, an appropriate status is sent, such as 401 or 405. The 417 Expectation Failed error is only returned when the server or response chain does not support expectations. If this message is received, the client resends the request without the Expect header.
Special consideration for clients
A client sending Expect: 100-continue is not required to wait for a specific length of time. The client proceeds to transmit the message body without first receiving a response. As HTTP/1.0 servers do not support expectations, when one is used as an intermediary, the client does not wait an indefinite period before transmitting the message body.
Special consideration for servers
If a server receives Expect: 100-continue as part of an HTTP/1.0 request, the expectation must be ignored. The server does not need to acknowledge with 100 if the message body has already been received or if no message body exists.
When a server sends 100, a final status such as 200 must ultimately follow unless the connection is dropped beforehand.
If a server responds with the final response before receiving the entire message body, the response indicates what the server intends to do with the connection: close the connection or continue reading and discard the request message.
Example
The client requests to send a 10K PDF file. The server responds with 417 Expectation Failed because expectations are not supported.
Request
PUT /docs HTTP/1.1
Host: example.com
Content-Type: application/pdf
Content-Length: 10000
Expect: 100-continue
Response
HTTP/1.1 417 Expectation Failed
Content-Type: text/html
Content-Length: 159
<html>
<head>
<title>Expectations not supported</title>
</head>
<body>
<p>Expectations are not supported by this server.
</p>
</body>
</html>
How to fix
Remove the Expect: 100-continue header and resend the request with the full body included. The server or an intermediary proxy does not support the 100-continue mechanism.
Many HTTP client libraries add the Expect: 100-continue header automatically for large payloads without explicit instruction. Disable this behavior at the library level:
Proxy and intermediary issues. HTTP/1.0 proxies, load balancers, and older gateways do not understand the Expect: 100-continue handshake. When the request passes through such an intermediary, the proxy rejects the request before the origin server processes the expectation. Upgrading the proxy or routing around HTTP/1.0 intermediaries resolves the issue in these environments.
On the server side, this status is rare in modern HTTP stacks. Most servers either honor Expect: 100-continue or silently ignore the header. Returning 417 is a deliberate signal to remove the expectation from the request.
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
Java
HttpServletResponse.SC_EXPECTATION_FAILED
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_EXPECTATION_FAILED
Angular
@angular/common/http/HttpStatusCode.ExpectationFailed