HTTP Headers
Content Location
The HTTP Content-Location
representation header indicates an alternate location for the returned data.
Its main use is to specify the URL of a resource transmitted as a result of content negotiation.
The Content-Location
header is distinct from the Location
header.
While Content-Location
points to the direct URL where the resource can be accessed after content negotiation, it allows the client to bypass future negotiations for this resource.
On the other hand, Location
indicates either the target URL of a redirect (3XX status codes) or the URL of a newly created resource in a 201 Created
response.
Syntax
Content-Location: <url>
Directives
- <url>
- A URL that can be either an absolute address or a relative path based on the current request URL. Absolute URLs specify the full path, including the protocol, domain, and resource location. Relative URLs define the location concerning the current document or request context, making links more flexible and adaptable across different environments.
Example
Requesting data from a server in different formats
Let’s say a site’s API can return data in JSON, XML, or CSV formats. If the URL for a particular document is at https://example.com/documents/foo
, the site could respond with different Content-Location headers depending on the Accept header sent by the client:
Request header | Response header |
---|---|
Accept: application/json, text/json | Content-Location: /documents/foo.json |
Accept: application/xml, text/xml | Content-Location: /documents/foo.xml |
Accept: text/plain, text/* | Content-Location: /documents/foo.txt |
The client can remember that the JSON version is available at the specified URL, skipping content negotiation for subsequent requests.
The server might also consider other content negotiation headers such as Accept-Language.
Similarly, the server could classify files using URL patterns like /documents/foo?format=json
.
When the form is submitted, the server generates a receipt. The server can use the Content-Location header to indicate where the receipt can be accessed later:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Location: /my-receipts/38
<!doctype html>
(Lots of HTML…)
<p>You sent $38.00 to ExampleUser.</p>
(Lots more HTML…)
How to Modify Header using Requestly
Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Content-Location header. This is especially useful for testing how your server handles resource redirection or content location during development or debugging. Steps to Modify the Content-Location 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 Content-Location.
- In the “Header Value” field, enter the URL or path you want to specify as the new content location (e.g., https://example.com/new-location).
- 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 Content-Location header into all matching requests, allowing you to simulate different content redirection scenarios and verify how your application or clients handle such changes.
You might need to modify the Content-Location header to test how your application handles content served from different URLs or locations. This helps ensure that your system correctly processes redirects or resource locations during development.
Table of Contents
- No headings found.