HTTP Headers
Expect
The HTTP Expect
request header specifies expectations that the server must meet to successfully process the entire request.
When a request includes the Expect: 100-continue
header, the server responds with a 100 Continue
status to indicate readiness to receive the remaining content. This mechanism is useful, especially when the client suspects that the request might fail, such as when sending requests that change server state without prior authenticated verification.
If the server cannot fulfill the expectation, it returns a 417 Expectation Failed
response. In other cases, it may respond with different status codes—such as a 4XX code indicating a client error or a 2XX code signaling successful processing without further actions needed.
Most common browsers typically do not send the Expect
header. However, some command-line tools and clients do so by default.
Syntax
Expect: 100-continue
Directives
There is only one defined expectation:
The 100-continue directive informs recipients that the client is about to send a (presumably large) message body in this request and wishes to receive a 100 Continue interim response.
Example
Examples
Large message body
A client sends a request with the Expect header and waits for the server to respond before transmitting the message body.
Example of such a request:
PUT /somewhere/fun HTTP/1.1
Host: origin.example.com
Content-Type: video/h264
Content-Length: 1234567890987
Expect: 100-continue
The server examines the headers and responds accordingly. If it sends a 100 Continue status, it indicates that the client should proceed with sending the message body:
HTTP/1.1 100 Continue
After receiving the continue response, the client completes the request by sending the actual data:
[Video data as content for PUT request]
How to Modify Header using Requestly
Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Accept header. This is especially useful for testing how your application responds to different media types during development or debugging. Steps to Modify the Accept Header:
- Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
- Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
- Add a new header modification:
- Under “Action”, select “Add” or “Override”.
- In the “Header Name” field, enter Accept.
- In the “Header Value” field, enter your preferred media type (e.g., text/html).
- Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
- Save the rule.
Once set up, Requestly will inject the Accept: text/html header into all matching requests, allowing you to simulate different client behaviors and test content negotiation on your server.
You might need to modify the Accept header to test how your app handles various response formats like JSON or XML. This helps ensure your backend sends the correct data based on what the client expects.
Table of Contents
- No headings found.