Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the HTTP header field “Content-Location”?

Confused/inspired by a comment to my question Do search engines respect the HTTP header field “Content-Location”?, I’d like to know, what the exact purpose of the Content-Location header field in HTTP is and how it can be used.

like image 560
Gumbo Avatar asked Jan 15 '09 17:01

Gumbo


People also ask

What is the purpose of HTTP headers?

An HTTP header is a field of an HTTP request or response that passes additional context and metadata about the request or response. For example, a request message can use headers to indicate it's preferred media formats, while a response can use header to indicate the media format of the returned body.

What is content location header?

The HTTP Content-Location header is an entity-header that gives another location for the data that is returned and also tells how to access the resource by indicating the direct URL. Its usage is often confused with another HTTP Header which is Location.

What are the contents in HTTP header?

An HTTP response header includes information in a text-record form that a Web server transmits back to the client's browser. The response header contains particulars such as the type, date and size of the file sent back by the server, as well as information regarding the server.

Why is the header line important in HTTP request messages?

The request-header fields allow the client to pass additional information about the request, and about the client itself, to the server.


2 Answers

In response to a GET request, Content-Location in HTTP can be used when a requested resource has multiple representations available, e.g. multiple languages. The selection of the resource returned will depend on the Accept headers in the original GET request.

Usually, the location specified in the Content-Location header is different to the location specified in the original request's URI.

In response to a PUT or POST request,

  • If the Content-Location URI is different than the requested URI, then the cache entry at the indicated URI is invalidated. (see https://www.rfc-editor.org/rfc/rfc7234#section-4.4 and https://www.rfc-editor.org/rfc/rfc2616#section-13.10)
  • If the Content-Location URI is the same as the requested URI, then that indicates to caches that the response to the PUT/POST request is the same as the response that would be received by a 200 response to a GET request at the same location and can thus be cached. (see https://www.rfc-editor.org/rfc/rfc7231#section-3.1.4.2) Note that Firefox and Chrome do not appear to implement this.
like image 116
Rob Wells Avatar answered Sep 22 '22 05:09

Rob Wells


Content-Location HTTP header is supposed to declare unique location of the resource that was used for a response to HTTP GET (e.g. request was GET /frontpage HTTP/1.1, the server may add HTTP header Content-Location: http://domain.com/frontpage.english.msie-optimized informing the user agent that if this specific response is needed later, the provided location should be used because the original location may depend on various things, which should then be explained via the "Vary" header).

However, note that HTTP Content-Location header is problematic in real world usage because different browsers (user agents) handle it differently: http://mail.python.org/pipermail/web-sig/2004-October/000985.html

This is because of RFC 2616 section 14.14 which says that "The value of Content-Location also defines the base URI for the entity". In short, a comforming user agent will compute the BASE URL for the fetched document using the Content-Location header which may result in different relative URLs being used if the fetched document does not define BASE url and real fetched URL and Content-Location differ enough (the "directory"/"path" part of the URL is different).

In addition, I've yet to see any advantage for using HTTP Content-Location (I once hoped that this could be used for hinting about permanent bookmark location in case currently viewed URL was volatile, such as domain.com/news/latest but that doesn't seem to be the case).

My current advice is forget about Content-Location for HTTP but you may use it for MIME email.

like image 26
Mikko Rantalainen Avatar answered Sep 20 '22 05:09

Mikko Rantalainen