HTTP Server header fields in a detailed

Source: Internet
Author: User

1. "Accept" field:

The HTTP Header contains a series of important information

such as status code, response type, file encoding, etc...

Alphabetical order

The first HTTP Header is an accept

Accept is only present in request

The meaning is: the type of media that can be accepted on 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

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)

Another example is that accept:text/* represents all of the text subclasses that are acceptable.

Accept can support multiple types that are separated by

e.g. accept:audio/*; q=0.2, Audio/basic to the effect that browsers prefer to audio/basic media types, but if you don't have this type, other audio types can

Here is a q=0.2, which is a value that represents the degree of relevance, the default value is one, in the order of the largest to the small

e.g. Accept:text/plain; q=0.5, text/html, Text/x-dvi; q=0.8, Text/x-c

The acceptable type precedence is as follows

1) text/html Text/x-c

2) Text/x-dvi

3) Text/plain

Q is a value between 0-1, the default value of Q is 1, q=0 is not acceptable (non acceptable)

Original Address (English): http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html


2, "accept-charset" field:

Accept-charset represents the character set supported by the browser

Example: accept-charset:iso-8859-1,utf-8;q=0.7,*;q=0.3

On behalf of this browser prefer the following character set

1) Favorite Iso-8859-1

2) then the Utf-8.

3) Last is * (all strings, no limit)

The corresponding response HTTP header field is Content-type

If the browser requests a character set that the server cannot respond to, then the server should return a 406 error

Note that this is only an identity bit, and the server also guarantees that the character set type used in the declaration and HTTP body must be consistent on the program.

For example, declare accept-charset:utf-8 in the HTTP header

But the text is GB2312 encoded ..... The browser is garbled--#


3, "accept-encoding" fields:

HTTP Header accept-encoding is the browser to the server, declaring the type of encoding supported by the browser, Python httpconnection default is the identitiy type.
Common with

accept-encoding:compress, gzip//support for Compress and gzip types
accept-encoding://default is Identity
accept-encoding: *//support all types
accept-encoding:compress;q=0.5, gzip;q=1.0//In order to support gzip, compress

accept-encoding:gzip;q=1.0, identity; q=0.5, *;q=0//sequentially supported gzip, identity

The corresponding type encoding header returned by the server is content-encoding

The rules for server processing accept-encoding are as follows

1. If the server can return any one of the Encoding types defined in accept-encoding, the processing succeeds (unless the value of Q equals 0, equals 0 is unacceptable)

2. * represents any type of encoding (except for the type of definition shown in accept-encoding)

3. If multiple encoding are matched at the same time, in the order of Q values

4. The identity is always an acceptable type of encoding (unless the token shown is of this type q=0), and if the value of accept-encoding is NULL then only the identity will be accepted

if all types of servers in accept-encoding are not returned, then a 406 error should be returned to the client

If the request does not have a accept-encoding then the server assumes that all Encoding are acceptable,

If there is an identity in accept-encoding, then the identity should be returned first (unless there is a definition of Q value, or you think the other type is more meaningful)

Note:

If the server does not support identity and the browser does not send accept-encoding, then the server should prefer to use "gzip" and "compress" in HTTP1.0, the server may follow the client type Send a more suitable type of encoding

most HTTP1.0 clients cannot process the Q value. and some servers, regardless of whether or not to pass the accept-encoding, will return the compressed data, so still want to monitor response content-encoding.


4, "Accept-language" field:

Languages and regions supported by the Accept-language browser in the HTTP header

He also supports multiple options and supports Q-values

such as accept-language:en-us,en;q=0.8

First-en, followed by en

Note: En-US is a standard American English representation, en for language is English US Representative area is the United States


5,"Cache-control" field

The cache of the Web page is controlled by the "Cache-control" in the HTTP message header, and the common values are private, No-cache, Max-age, must-revalidate, etc., and the default is private. Its function is divided into the following situations according to different ways of re-browsing:

(1) Open a new window

If the value of the specified Cache-control is private, No-cache, Must-revalidate, the server will be re-accessed when the new window is opened. If you specify a max-age value, 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

If the value is private or must-revalidate (not the same as on the Web), the server will be accessed only on the first visit and will not be accessed at a later time. If the value is No-cache, it is accessed every time. If the value is Max-age, access is not repeated until it expires.

(3) Press Back button

If the value is private, must-revalidate, max-age, it is not re-accessed, and if it is no-cache, it is repeated every time

(4) Press the Refresh button

No matter what the value, it will be accessed repeatedly


6, "Connection" field

Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "keep-alive", or sees the request using an HTTP 1.1 (HTTP 1.1 is persistent by default), it can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), Significantly reduce the time it takes to download. To do this, the servlet needs to send a content-length header in the answer, and the simplest implementation is to write the content to Bytearrayoutputstream first and then calculate its size before formally writing the content.



HTTP Server header fields in a detailed

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.