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.
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.
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.
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.
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.
PUT /docs HTTP/1.1 Host: www.example.ai Content-Type: applications/pdf Content-Length: 10000 Expect: 100-continue
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>
Apache HttpComponents Core
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.