Header header parsing for HTTP requests

Source: Internet
Author: User

Request Headers:

Is that I visited a URL: a header of http://www.hzau.edu.cn , According to the concrete example to analyze the function of each part and its function.

Accept

Role: The type of media that can be accepted by the browser side ,

For example, accept:text/html represents the type of server postback that the browser can accept as text/html , which is what we often call HTML documents /c5>,

If the server cannot return data of type text/html , the server should return a 406 error (non acceptable)

Wildcard * represents any type

For example, Accept: */* on behalf of the browser can handle all types , ( the General browser to the server is the issue of this )

Accept-encoding:

Function: The browser declares itself to receive the encoding method, usually specifies the compression method, whether compression is supported, what compression method is supported (gzip,deflate), (note: This is not a character encoding) ;

Example: accept-encoding:zh-cn,zh;q=0.8

Accept-language

Role: The browser affirms the language it receives.

Language and Character set differences: Chinese is a language, Chinese has a variety of character sets, such as Big5,gb2312,gbk and so on;

Example: accept-language:en-us

Connection

Example: connection:keep-alive When a Web page is opened, TCP for transmitting HTTP data between the client and the server The connection will not be closed, and if the client accesses the Web page on this server again, it will continue to use the established connection

For example: connection:close represents a Request to be completed, between the client and the server for the transfer of HTTP data TCP the connection is closed when the client sends again Request , the need to re-establish TCP connection.

Host(the header field is required when the request is sent)

Role : The request header domain is used primarily to specify the Internet host and port number of the requested resource, which is typically extracted from the HTTP URL

For example : We entered in the browser:http://www.hzau.edu.cn

In the request message sent by the browser, the Host request Header field is included, as follows:

Host:www.hzau.edu.cn

The default port number is used here, and if a port number is specified, it becomes:Host: Specify port number

Referer

When the browser sends a request to the Web server, it usually takes Refererand tells the server which page link I took from, and the server can get some information for processing. For example, if you link to a friend from my home page, his server will be able to count the number of users who click on the link on my page to visit his website from HTTP Referer .

User-agent

Role: Tells the HTTP server which client uses the name and version of the operating system and browser .

When we go online to the forum, often see some welcome information, which lists the name and version of your operating system, the name and version of the browser you are using, which often makes a lot of people feel amazing, in fact, the server application is from user-agent This request is obtained in the header domain of the user-agent request header domain that allows the client to tell the server about its operating system, browser, and other properties.

For example: user-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; trident/4.0; CIBA;. NET CLR 2.0.50727;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729;. net4.0c; infopath.2;. NET4.0E)

Also, whenaccessing some other URLs , some other fields in the Header of therequest are listed below:

For example, when I log in to a Web site that requires a username and password, the Request Header contains fields that are not mentioned above.



C Ache-control

The cache control of our web page is implemented by the "cache-control" in the HTTP header, and the common values are private, No-cache,max-age,must-revalidate , etc., default to private . The effects of these values are differentiated according to the different ways in which a page is re-viewed:

(1), open a new window

The value is private,no-cache,must-revalidate, and the server will be re-accessed when a new window is opened. If you specify a max-age value (in seconds), the server is not re-accessed in the time within this value, for example:

Cache-control:max-age=5 (indicates that access will not go to the server within 5 seconds of accessing this page )

(2), enter in the address bar

A value of private or must-revalidate will only access the server on the first visit and will no longer be accessed at a later time.

The value is no-cache, which is accessed every time.

A value of max-age, the access is not repeated until it expires.

(3), press the Back button

The value is private,must-revalidate,max-age, and is not re-accessed.

A value of No-cache, which is repeatedly accessed every time

(4), press the Refresh button

No matter what the value, it will be accessed repeatedly


Cookies

Cookies are used to store some user information so that the server can identify the user (most of the sites that need to sign in are more common), such as cookies that store user names and passwords for some users. When the user logs in, it will generate a cookie on the client to store the information, so that the browser can read the cookie information to the server to verify and pass, it will determine that you are a legitimate user, This allows you to view the corresponding page. Of course , the data in the cookie is not only the above range, but also a lot of information can be stored in the cookie , such as SessionID and so on.

If-modified-since

Effect: The last modification time of the browser-side cache page is sent to the server, and the server compares this time with the last modification time of the actual file on the server. If the time is consistent, then return 304, the client uses the local cache file directly. If the time is inconsistent, The contents of the new file are returned. After the client receives it, it discards the old files, caches the new files, and displays them in the browser .

For example:Mon, 12:03:33 GMT

If-none-match

Role: If-none-matchand theETagWorking together, the principle ofHTTP Responseadded inETaginformation. When the user requests the resource again, theHTTP RequestJoin inIf-none-matchInformation(ETagthe value). If the server verifies that the resourceETaghas not changed (the resource is not updated), it will return a304The status tells the client to use the local cache file. Otherwise it will return $State and new resources andEtag. using such a mechanism will improve the performance of your website

Example : If-none-match: w/"3119-1437038474000"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Header header parsing for HTTP requests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.