Wednesday, January 1, 2014

HTTP Headers

HTTP headers are a core part of HTTP requests and responses. With every request and response HTTP headers goes back and forth. You can open the browser console or use a tool like firebug to see these information. 

HTTP headers are name-value pairs. Cookie data will also get transferred with HTTP headers. Most of the headers are optional. 

GET is the main method used to retrieve HTML, JavaScript, images from the server. POST is used to send data to the server. HEAD is used to retrieve header information. 

For every request, server will return HTTP protocol been used and the status code. Each status code is a number with a special meaning.

  • 200's are used for successful requests.
  • 300's are for redirections.
  • 400's are used if there was a problem with the request.
  • 500's are used if there was a problem with the server.

Common Headers in HTTP Requests

User Agent : Browser name/version, OS and version, Default language

Accept encoding : Most modern browsers support gzip. The web server can then send HTML output in compressed format which will reduce the response size.

If-Modified-since : if the document is already cached and if you visit again browser can check if it has modified

Cookie : Sends cookies stored in the browser for that domain

Referrer : Referring URL

Host : domain name with sub domain

Accept Language : Default language setting of the user.

Authorization : When a web page asks for authorization, the browser opens a login window. When you send username and password, the browser sends another HTTP request with a header with username and password. The header information are base64 encoded.  
see here

Common Headers in HTTP Responses

Cache-control
Specify things that should be obeyed by all caching mechanisms. 
  • public : response maybe cached by anyone
  • max-age : how many seconds the cache is valid for
  • to prevent caching you can use no-cache directive. 
Google Developers - HTTP Caching - Cache Control
Mobify.com - Beginners guide to http cache headers

Content type
indicates mime-type of the document. 
MIME types

Content length

Pragma
http://stackoverflow.com/questions/10314174/difference-between-pragma-and-cache-control-headers
http://stackoverflow.com/questions/1920781/what-does-the-http-header-pragma-public-mean

Etag
Used with caching, Server may send this with every document it serves, This value is used to determine whether to the content is new or not.

Last modified

Set cookie
When the website wants to set or update the cookie in the browser it'll use this.

If you're sending multiple cookies, they are combined and sent as comma-separated values. But this is treated in different ways in different browsers.

References
http://code.tutsplus.com/tutorials/http-headers-for-dummies--net-8039

0 comments:

Post a Comment

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook