http accept and content-type headers confusion

potato

This is an example of HTTP request message transmitted to the web server. Inside headers there is an Accept header. I am confused about the meaning of it and how it is created. I thought it solely specifies my browsers capabilities to handle files. But that doesn't explain why does it differ when I visit amazon.com or joes-hardware.

There is also Content-Type header, which is a MIME for a file it requested. Same question. How does my browser know what is the type of file it requested? Is it based on the URI extension I requested or is this a generic header? This header seems to only be send in response headers. My mistake.

GET /tools.html HTTP/1.0
User-agent: Mozilla/4.75 [en] (Win98; U) Host: www.joes-hardware.com
Accept: text/html, image/gif, image/jpeg 
Accept-language: en
DaSourcerer

First things first: Acceptand Accept-Language are headers defined in RFC 7231, section 5.3.2 and section 5.3.5, respectively. Together with Accept-* headers, they enable content negotiation through the client. There is an excellent article regarding content engotiation on the Mozilla Development Network. (On a side-note: The MDN is an excellent starting point for research. A lot of the articles are outdated, but the concepts are still largely valid)

The content of the Accept-Language is largely controlled by the language settings of a client's UI. Mozilla's Firefox (and - IIRC - Opera and Safari) allows to tweak these through its settings while MSIE seems to deduct them from the keyboard layouts installed in the system. There is nothing in the type of requested media that should influence this header.

The content of the Accept header on the other hand is very much depending on the context in which a resource is being requested. E.g. if you request a resource through your browser's address bar, the Accept header will pretty much read like "give me anything I can digest." If the browser is requesting a resource through an <img/>-tag, the header is going to differ in that the browser is trying to get a presentation of the requested resource that is fit for being displayed inside that tag. Same for <video/>, <audio/>, and <script/>.

Beyond that, I am not aware of any mechanisms effecting the Accept header. <a/>-tags have - unknownst to most - a type attribute which is carrying a MIME mediatype. This is, however, a fallback mechanism and should not alter Accept in any way.

As for your example, I took the liberty of requesting both sites and copying the relevant request headers:

amazon.com

GET / HTTP/1.1
Host: www.amazon.com
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

joes-hardware.com

GET / HTTP/1.1
Host: www.joes-hardware.com
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

The headers are no different when requesting /tools.html in the last example.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

http accept and content-type headers confusion

From Dev

Akka-http: Accept and Content-type handling

From Dev

Adding Content-Type Headers to Java HTTP echo server

From Dev

Can I specify Accept and Content-Type headers in Guzzle's routes file?

From Dev

sendGrid set headers/content type

From Dev

sendGrid set headers/content type

From Dev

Server cannot set content type after HTTP headers have been sent on rowcommand

From Dev

Server cannot set content type after HTTP headers have been sent on rowcommand

From Dev

Angular 2 headers with 'content-type' : 'text/xml', http post not working

From Dev

Call URL with Basic Authentication with Accept and Content Type

From Dev

Alamofire Accept and Content-Type JSON

From Dev

Android HTTP calls not setting Accept-Language headers?

From Dev

Is cookie part of the header of a http request/response? Is it a key value pair? How different is it than Accept or Content-type header keys?

From Dev

linux mail adding content type headers not working

From Dev

Confusion: AngularJS $http POST response is returning HTML content of index file

From Dev

phpunit and http content-type

From Dev

dllexport in headers confusion

From Dev

Header parameters: "Accept" and "Content-type" in a REST context

From Dev

Should response Content-Type always be same as Accept?

From Dev

How to validate an input type="text" element to only accept certain content?

From Dev

Accept Only JSON Content Type In A Post or Put Request In ExpressJS

From Dev

WCF WebInvoke which can accept content-type: text/plain?

From Dev

AWS API Gateway accept Content-type: application/xml

From Dev

Does get request need content type and accept header?

From Dev

Accept Only JSON Content Type In A Post or Put Request In ExpressJS

From Dev

ASP.NET MVC: Programmatically set HTTP headers on static content

From Dev

Addon to modify http headers specified via regex of content

From Dev

file_get_contents returns HTTP headers in content

From Dev

Akka Http - how to read Content-Disposition from HttpResponse headers?

Related Related

  1. 1

    http accept and content-type headers confusion

  2. 2

    Akka-http: Accept and Content-type handling

  3. 3

    Adding Content-Type Headers to Java HTTP echo server

  4. 4

    Can I specify Accept and Content-Type headers in Guzzle's routes file?

  5. 5

    sendGrid set headers/content type

  6. 6

    sendGrid set headers/content type

  7. 7

    Server cannot set content type after HTTP headers have been sent on rowcommand

  8. 8

    Server cannot set content type after HTTP headers have been sent on rowcommand

  9. 9

    Angular 2 headers with 'content-type' : 'text/xml', http post not working

  10. 10

    Call URL with Basic Authentication with Accept and Content Type

  11. 11

    Alamofire Accept and Content-Type JSON

  12. 12

    Android HTTP calls not setting Accept-Language headers?

  13. 13

    Is cookie part of the header of a http request/response? Is it a key value pair? How different is it than Accept or Content-type header keys?

  14. 14

    linux mail adding content type headers not working

  15. 15

    Confusion: AngularJS $http POST response is returning HTML content of index file

  16. 16

    phpunit and http content-type

  17. 17

    dllexport in headers confusion

  18. 18

    Header parameters: "Accept" and "Content-type" in a REST context

  19. 19

    Should response Content-Type always be same as Accept?

  20. 20

    How to validate an input type="text" element to only accept certain content?

  21. 21

    Accept Only JSON Content Type In A Post or Put Request In ExpressJS

  22. 22

    WCF WebInvoke which can accept content-type: text/plain?

  23. 23

    AWS API Gateway accept Content-type: application/xml

  24. 24

    Does get request need content type and accept header?

  25. 25

    Accept Only JSON Content Type In A Post or Put Request In ExpressJS

  26. 26

    ASP.NET MVC: Programmatically set HTTP headers on static content

  27. 27

    Addon to modify http headers specified via regex of content

  28. 28

    file_get_contents returns HTTP headers in content

  29. 29

    Akka Http - how to read Content-Disposition from HttpResponse headers?

HotTag

Archive