Http 简明教程

HTTP - Header Fields

HTTP 头字段提供关于请求或响应所需的信息,或关于在消息正文中发送的对象的信息。有四种类型的 HTTP 响应消息头:

HTTP header fields provide required information about the request or response, or about the object sent in the message body. There are four types of HTTP message headers:

  1. General-header: These header fields have general applicability for both request and response messages.

  2. Client Request-header: These header fields have applicability only for request messages.

  3. Server Response-header: These header fields have applicability only for response messages.

  4. Entity-header: These header fields define meta information about the entity-body or, if no body is present, about the resource identified by the request.

General Headers

Cache-Control

Cache-Control通用头字段用于指定所有缓存系统都必须遵守的指令。以下是语法:

The Cache-Control general-header field is used to specify directives that MUST be obeyed by all the caching system. The syntax is as follows:

Cache-Control : cache-request-directive|cache-response-directive

HTTP客户端或服务器可以使用`@ {s0}`通用标头为缓存指定参数,或从缓存中请求某些类型的文档。缓存指令已逗号分隔列表中指定。例如:

An HTTP client or server can use the Cache-control general header to specify parameters for the cache or to request certain kinds of documents from the cache. The caching directives are specified in a comma-separated list. For example:

Cache-control: no-cache

下表列出了客户端可以在其 HTTP 请求中使用的重要缓存请求指令:

The following table lists the important cache request directives that can be used by the client in its HTTP request:

S.N.

Cache Request Directive and Description

1

*no-cache*A cache must not use the response to satisfy a subsequent request without successful revalidation with the origin server.

2

*no-store*The cache should not store anything about the client request or server response.

3

*max-age = seconds*Indicates that the client is willing to accept a response whose age is not greater than the specified time in seconds.

4

*max-stale [ = seconds ]*Indicates that the client is willing to accept a response that has exceeded its expiration time. If seconds are given, it must not be expired by more than that time.

5

*min-fresh = seconds*Indicates that the client is willing to accept a response whose freshness lifetime is not less than its current age plus the specified time in seconds.

6

*no-transform*Does not convert the entity-body.

7

*only-if-cached*Does not retrieve new data. The cache can send a document only if it is in the cache, and should not contact the origin-server to see if a newer copy exists.

以下重要的缓存响应指令可以由服务器在其 HTTP 响应中使用:

The following important cache response directives that can be used by the server in its HTTP response:

S.N.

Cache Response Directive and Description

1

*public*Indicates that the response may be cached by any cache.

2

*private*Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.

3

*no-cache*A cache must not use the response to satisfy a subsequent request without successful re-validation with the origin server.

4

*no-store*The cache should not store anything about the client request or server response.

5

*no-transform*Does not convert the entity-body.

6

*must-revalidate*The cache must verify the status of the stale documents before using it and expired ones should not be used.

7

*proxy-revalidate*The proxy-revalidate directive has the same meaning as the must- revalidate directive, except that it does not apply to non-shared user agent caches.

8

*max-age = seconds*Indicates that the client is willing to accept a response whose age is not greater than the specified time in seconds.

9

*s-maxage = seconds*The maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header. The s-maxage directive is always ignored by a private cache.

Connection

Connection通用头字段允许发送方指定该特定连接所需选项,并且不能通过代理在进一步连接中传达这些选项。以下是使用连接标头的简单语法:

The Connection general-header field allows the sender to specify options that are desired for that particular connection and must not be communicated by proxies over further connections. Following is the simple syntax for using connection header:

Connection : "Connection"

HTTP/1.1为发送方定义了“close”连接选项,以表示在完成响应后将关闭该连接。例如:

HTTP/1.1 defines the "close" connection option for the sender to signal that the connection will be closed after completion of the response. For example:

Connection: close

默认情况下,HTTP 1.1使用持久连接,其中连接不会在事务后自动关闭。另一方面,HTTP 1.0默认情况下没有持久连接。如果1.0客户端希望使用持久连接,它将使用`@ {s1}`参数,如下所示:

By default, HTTP 1.1 uses persistent connections, where the connection does not automatically close after a transaction. HTTP 1.0, on the other hand, does not have persistent connections by default. If a 1.0 client wishes to use persistent connections, it uses the keep-alive parameter as follows:

Connection: keep-alive

Date

所有HTTP日期/时间戳都必须以格林尼治标准时间(GMT)表示,无一例外。HTTP应用程序可以使用以下三种日期/时间戳表示形式中的任何一种:

All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception. HTTP applications are allowed to use any of the following three representations of date/time stamps:

Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

这里第一个格式是最常用的格式。

Here the first format is the most preferred one.

Pragma

Pragma general-header 域用于包含在请求/响应链中的任何收件人可能适用的特定于实现的指令。例如:

The Pragma general-header field is used to include implementation specific directives that might apply to any recipient along the request/response chain. For example:

Pragma: no-cache

HTTP/1.0 中定义的唯一指令为 no-cache 指令,且为了向后兼容而维持在 HTTP 1.1 中。将来不会再定义新的 Pragma 指令。

The only directive defined in HTTP/1.0 is the no-cache directive and is maintained in HTTP 1.1 for backward compatibility. No new Pragma directives will be defined in the future.

Trailer

Trailer general 域值表明给定头域集存在于使用分块传输编码编码的消息预告中。以下是 Trailer 头域的语法:

The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding. Following is the syntax of Trailer header field:

Trailer : field-name

Trailer 头域中列出的消息头域不得包含以下头域:

Message header fields listed in the Trailer header field must not include the following header fields:

  1. Transfer-Encoding

  2. Content-Length

  3. Trailer

Transfer-Encoding

Transfer-Encoding 通用头字段指示为了在发送方和接收方之间安全地传输消息正文而对消息正文应用了哪种类型的转换。这与 content-encoding 不同,因为传输编码是消息的属性,而不是实体正文的属性。Transfer-Encoding 头字段的语法如下:

The Transfer-Encoding general-header field indicates what type of transformation has been applied to the message body in order to safely transfer it between the sender and the recipient. This is not the same as content-encoding because transfer-encodings are a property of the message, not of the entity-body. The syntax of Transfer-Encoding header field is as follows:

Transfer-Encoding: chunked

所有传输编码值不区分大小写。

All transfer-coding values are case-insensitive.

Upgrade

Upgrade 通用标题允许客户端指定其支持的其他通信协议,如果服务器发现切换协议合适,则客户端希望使用这些协议。例如:

The Upgrade general-header allows the client to specify what additional communication protocols it supports and would like to use if the server finds it appropriate to switch protocols. For example:

Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11

Upgrade 头字段旨在为从 HTTP/1.1 过渡到其他不兼容协议提供一种简单的机制。

The Upgrade header field is intended to provide a simple mechanism for transition from HTTP/1.1 to some other, incompatible protocol.

Via

网关和代理必须使用 Via 通用头字段来指示中间协议和接收者。例如,请求消息可以从 HTTP/1.0 用户代理发送到内部代理(代号为“fred”),该代理使用 HTTP/1.1 将请求转发到 nowhere.com 上的公共代理,该代理通过将请求转发到 www.ics.uci.edu 上的原始服务器来完成请求。然后,www.ics.uci.edu 收到的请求将具有以下 Via 头字段:

The Via general-header must be used by gateways and proxies to indicate the intermediate protocols and recipients. For example, a request message could be sent from an HTTP/1.0 user agent to an internal proxy code-named "fred", which uses HTTP/1.1 to forward the request to a public proxy at nowhere.com, which completes the request by forwarding it to the origin server at www.ics.uci.edu. The request received by www.ics.uci.edu would then have the following Via header field:

Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)

Upgrade 头字段旨在为从 HTTP/1.1 过渡到其他不兼容协议提供一种简单的机制。

The Upgrade header field is intended to provide a simple mechanism for transition from HTTP/1.1 to some other, incompatible protocol.

Warning

Warning 通用标题用于携带有关消息状态或转换的其他信息,这些信息可能不会反映在消息中。响应可能携带多个 Warning 标题。

The Warning general-header is used to carry additional information about the status or transformation of a message which might not be reflected in the message. A response may carry more than one Warning header.

Warning : warn-code SP warn-agent SP warn-text SP warn-date

Client Request Headers

Accept

可以将 Accept 请求标头域用于指定对响应可接受的某些媒体类型。以下是其一般语法:

The Accept request-header field can be used to specify certain media types which are acceptable for the response. The general syntax is as follows:

Accept: type/subtype [q=qvalue]

可以列出用逗号分隔的多个媒体类型,并且可选的 qvalue 表示在 0 到 1 的范围内接受类型的可接受质量级别。以下是一个示例:

Multiple media types can be listed separated by commas and the optional qvalue represents an acceptable quality level for accept types on a scale of 0 to 1. Following is an example:

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

它将解释为 text/htmltext/x-c ,是首选媒体类型,但如果它们不存在,则发送 text/x-dvi 实体,如果那不存在,则发送 text/plain 实体。

This would be interpreted as text/html and text/x-c and are the preferred media types, but if they do not exist, then send the text/x-dvi entity, and if that does not exist, send the text/plain entity.

Accept-Charset

Accept-Charset 请求头字段可用于指示响应可以接受哪些字符集。以下是基本语法:

The Accept-Charset request-header field can be used to indicate what character sets are acceptable for the response. Following is the general syntax:

Accept-Charset: character_set [q=qvalue]

多个字符集可以通过逗号分隔列出,可选的 qvalue 表示非首选字符集的可接受质量级别(范围 0 到 1)。以下是一个示例:

Multiple character sets can be listed separated by commas and the optional qvalue represents an acceptable quality level for nonpreferred character sets on a scale of 0 to 1. Following is an example:

Accept-Charset: iso-8859-5, unicode-1-1; q=0.8

特殊值 " ", if present in the *Accept-Charset 字段与所有字符集匹配,并且如果不存在 Accept-Charset 头,则默认为可接受任何字符集。

The special value "", if present in the *Accept-Charset field, matches every character set and if no Accept-Charset header is present, the default is that any character set is acceptable.

Accept-Encoding

Accept-Encoding 请求标头域与 Accept 类似,但会限制响应中可接受的内容编码。以下是其一般语法:

The Accept-Encoding request-header field is similar to Accept, but restricts the content-codings that are acceptable in the response. The general syntax is:

Accept-Encoding: encoding types

以下是示例:

Examples are as follows:

Accept-Encoding: compress, gzip
Accept-Encoding:
Accept-Encoding: *
Accept-Encoding: compress;q=0.5, gzip;q=1.0
Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0

Accept-Language

Accept-Language 请求标头域与 Accept 类似,但会限制请求响应时首选的一组自然语言。以下是其一般语法:

The Accept-Language request-header field is similar to Accept, but restricts the set of natural languages that are preferred as a response to the request. The general syntax is:

Accept-Language: language [q=qvalue]

可以使用逗号分隔方式列出多种语言,并且可选的 qvalue 表示非首选语言在 0 到 1 的范围内可接受的质量级别。以下是一个示例:

Multiple languages can be listed separated by commas and the optional qvalue represents an acceptable quality level for non preferred languages on a scale of 0 to 1. Following is an example:

Accept-Language: da, en-gb;q=0.8, en;q=0.7

Authorization

Authorization 请求标头域值包含凭证,其中包含用户代理的认证信息,用于请求资源的领域。以下是其一般语法:

The Authorization request-header field value consists of credentials containing the authentication information of the user agent for the realm of the resource being requested. The general syntax is:

Authorization : credentials

HTTP/1.0 规范定义了 BASIC 授权方案,其中授权参数为 username:password ,用 base64 编码。以下是一个示例:

The HTTP/1.0 specification defines the BASIC authorization scheme, where the authorization parameter is the string of username:password encoded in base 64. Following is an example:

Authorization: BASIC Z3Vlc3Q6Z3Vlc3QxMjM=

该值解码为 guest:guest123 ,其中 guest 是用户 ID, guest123 是密码。

The value decodes into is guest:guest123 where guest is user ID and guest123 is the password.

Cookie 请求头字段的值包含存储用于该 URL 的信息的名/值对。以下是基本语法:

The Cookie request-header field value contains a name/value pair of information stored for that URL. Following is the general syntax:

Cookie: name=value

多个 Cookie 可以用分号分隔来指定,如下所示:

Multiple cookies can be specified separated by semicolons as follows:

Cookie: name1=value1;name2=value2;name3=value3

Expect

Expect 请求标头域用于表明客户端需要特定的一组服务器行为。以下是其一般语法:

The Expect request-header field is used to indicate that a particular set of server behaviors is required by the client. The general syntax is:

Expect : 100-continue | expectation-extension

如果服务器收到包含 Expect 字段的请求,该字段包含其不支持的期望扩展,则它必须以 417(期望失败)状态进行响应。

If a server receives a request containing an Expect field that includes an expectation-extension that it does not support, it must respond with a 417 (Expectation Failed) status.

From

From 请求头字段包含控制请求用户代理的人员的互联网电子邮件地址。以下是一个简单的示例:

The From request-header field contains an Internet e-mail address for the human user who controls the requesting user agent. Following is a simple example:

From: webmaster@w3.org

此头字段可用于记录目的以及作为识别无效或不需要的请求的源的工具。

This header field may be used for logging purposes and as a means for identifying the source of invalid or unwanted requests.

Host

Host 请求标头域用于指定所请求资源的 Internet 主机和端口号。以下是其一般语法:

The Host request-header field is used to specify the Internet host and the port number of the resource being requested. The general syntax is:

Host : "Host" ":" host [ ":" port ] ;

不带任何尾随端口信息的 host 表示默认端口 80。例如,[role="bare"] [role="bare"]http://www.w3.org/pub/WWW/ 上对来源服务器的请求将为:

A host without any trailing port information implies the default port, which is 80. For example, a request on the origin server for [role="bare"]http://www.w3.org/pub/WWW/ would be:

GET /pub/WWW/ HTTP/1.1
Host: www.w3.org

If-Match

If-Match 请求标头域与方法一起使用以使其成为条件方法。仅当此标记中给定的值与 ETag 所表示的给定实体标记相匹配时,此标头才请求服务器执行所请求的方法。以下是其一般语法:

The If-Match request-header field is used with a method to make it conditional. This header requests the server to perform the requested method only if the given value in this tag matches the given entity tags represented by ETag. The general syntax is:

If-Match : entity-tag

星号 (*) 匹配任何实体,且仅当实体存在时事务才会继续。以下是一些可能的示例:

An asterisk (*) matches any entity, and the transaction continues only if the entity exists. Following are possible examples:

If-Match: "xyzzy"
If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-Match: *

如果没有任何实体标记匹配,或者给出了 "*" 且没有任何当前实体存在,则服务器不得执行请求的方法,并且必须返回 412(前提条件失败)响应。

If none of the entity tags match, or if "*" is given and no current entity exists, the server must not perform the requested method, and must return a 412 (Precondition Failed) response.

If-Modified-Since

If-Modified-Since 请求标头域与方法一起使用以使其成为条件方法。如果在该字段中指定的时间之后没有修改所请求的 URL,则服务器不会返回实体;相反,将返回 304(未修改)响应而不具有任何消息体。if-modified-since 的一般语法如下:

The If-Modified-Since request-header field is used with a method to make it conditional. If the requested URL has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message-body. The general syntax of if-modified-since is:

If-Modified-Since : HTTP-date

该字段的一个示例是:

An example of the field is:

If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT

如果没有任何实体标记匹配,或者给出了 "*" 且没有任何当前实体存在,则服务器不得执行请求的方法,并且必须返回 412(前提条件失败)响应。

If none of the entity tags match, or if "*" is given and no current entity exists, the server must not perform the requested method, and must return a 412 (Precondition Failed) response.

If-None-Match

If-None-Match 请求标头域与方法一起使用以使其成为条件方法。仅当此标记中给定的值之一与 ETag 所表示的给定实体标记相匹配时,此标头才请求服务器执行所请求的方法。以下是其一般语法:

The If-None-Match request-header field is used with a method to make it conditional. This header requests the server to perform the requested method only if one of the given value in this tag matches the given entity tags represented by ETag. The general syntax is:

If-None-Match : entity-tag

星号 (*) 匹配任何实体,并且仅当实体不存在时交易才继续。以下是一些可能的示例:

An asterisk (*) matches any entity, and the transaction continues only if the entity does not exist. Following are the possible examples:

If-None-Match: "xyzzy"
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-None-Match: *

If-Range

If-Range 请求标头域可以与条件 GET 配合使用,仅请求丢失的实体部分(如果实体未被更改)以及(如果实体被更改)整个实体。以下是其一般语法:

The If-Range request-header field can be used with a conditional GET to request only the portion of the entity that is missing, if it has not been changed, and the entire entity if it has been changed. The general syntax is as follows:

If-Range : entity-tag | HTTP-date

可以实体标记或日期来标识已收到的部分实体。例如:

Either an entity tag or a date can be used to identify the partial entity already received. For example:

If-Range: Sat, 29 Oct 1994 19:43:31 GMT

如果在给定日期之后没有修改文档,则服务器返回 Range 标头给出的字节范围,否则,返回所有新文档。

Here if the document has not been modified since the given date, the server returns the byte range given by the Range header, otherwise it returns all of the new document.

If-Unmodified-Since

If-Unmodified-Since 请求标头域与方法一起使用以使其成为条件方法。以下是其一般语法:

The If-Unmodified-Since request-header field is used with a method to make it conditional. The general syntax is:

If-Unmodified-Since : HTTP-date

如果请求的资源自该字段中指定的时间以来未被修改,则服务器应像 If-Unmodified-Since 标头不存在那样执行请求的操作。例如:

If the requested resource has not been modified since the time specified in this field, the server should perform the requested operation as if the If-Unmodified-Since header were not present. For example:

If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT

如果请求导致的结果不是 2xx 或 412 状态,则应忽略 If-Unmodified-Since 标头。

If the request results in anything other than a 2xx or 412 status, the If-Unmodified-Since header should be ignored.

Max-Forwards

Max-Forwards 请求标头域提供了一个利用 TRACE 和 OPTIONS 方法来限制可以将请求转发到下一个入站服务器的代理或网关的数量的机制。以下是其一般语法:

The Max-Forwards request-header field provides a mechanism with the TRACE and OPTIONS methods to limit the number of proxies or gateways that can forward the request to the next inbound server. Here is the general syntax:

Max-Forwards : n

Max-Forwards 值是一个十进制整数,表示此请求消息可以被转发的剩余次数。这对于用 TRACE 方法进行调试非常有用,可以避免无限循环。例如:

The Max-Forwards value is a decimal integer indicating the remaining number of times this request message may be forwarded. This is useful for debugging with the TRACE method, avoiding infinite loops. For example:

Max-Forwards : 5

Max-Forwards 标头字段可以忽略 HTTP 规范中定义的所有其他方法。

The Max-Forwards header field may be ignored for all other methods defined in the HTTP specification.

Proxy-Authorization

Proxy-Authorization 请求标头字段允许客户端向要求身份验证的代理(或其用户)标识自身。以下是通用语法:

The Proxy-Authorization request-header field allows the client to identify itself (or its user) to a proxy which requires authentication. Here is the general syntax:

Proxy-Authorization : credentials

Proxy-Authorization 字段值包含凭据,其中包含用户代理针对被请求资源的代理和/或域的认证信息。

The Proxy-Authorization field value consists of credentials containing the authentication information of the user agent for the proxy and/or realm of the resource being requested.

Range

Range 请求标头字段指定从文档请求的部分内容范围。通用语法为:

The Range request-header field specifies the partial range(s) of the content requested from the document. The general syntax is:

Range: bytes-unit=first-byte-pos "-" [last-byte-pos]

byte-range-spec 中的 first-byte-pos 值给了范围中第一个字节的字节偏移。而 last-byte-pos 值给出了范围中最后一个字节的字节偏移;也就是说,指定的字节位置包含在内。您可以将字节单位指定为字节。字节偏移从零开始。以下是一些简单的示例:

The first-byte-pos value in a byte-range-spec gives the byte-offset of the first byte in a range. The last-byte-pos value gives the byte-offset of the last byte in the range; that is, the byte positions specified are inclusive. You can specify a byte-unit as bytes. Byte offsets start at zero. Some simple examples are as follows:

- The first 500 bytes
Range: bytes=0-499

- The second 500 bytes
Range: bytes=500-999

- The final 500 bytes
Range: bytes=-500

- The first and last bytes only
Range: bytes=0-0,-1

多个范围可以使用逗号分隔来列出。如果逗号分隔的字节范围内的第一个数字丢失,则该范围从文档结尾开始计。如果第二个数字丢失,则该范围从字节 n 开始到文档的结尾。

Multiple ranges can be listed, separated by commas. If the first digit in the comma-separated byte range(s) is missing, the range is assumed to count from the end of the document. If the second digit is missing, the range is byte n to the end of the document.

Referer

Referer 请求标头字段允许客户端指定已从其请求 URL 的资源的地址(URI)。通用语法如下:

The Referer request-header field allows the client to specify the address (URI) of the resource from which the URL has been requested. The general syntax is as follows:

Referer : absoluteURI | relativeURI

以下是一个简单的示例:

Following is a simple example:

Referer: http://www.tutorialspoint.org/http/index.htm

如果字段值是相对 URI,则应相对于 Request-URI 进行解释。

If the field value is a relative URI, it should be interpreted relative to the Request-URI.

TE

TE 请求头字段表明其可能在哪种扩展传输编码中接受响应,以及是否可能接受块传输编码中的拖尾字段。以下是一般语法:

The TE request-header field indicates what extension transfer-coding it is willing to accept in the response and whether or not it is willing to accept trailer fields in a chunked transfer-coding. Following is the general syntax:

TE   : t-codings

关键字“trailers”的存在表明该客户端愿意在块传输编码中接受拖尾字段,并且可以指定为以下两种方式之一:

The presence of the keyword "trailers" indicates that the client is willing to accept trailer fields in a chunked transfer-coding and it is specified either of the ways:

TE: deflate
TE:
TE: trailers, deflate;q=0.5

如果 TE 字段值为 null 或没有 TE 字段,则仅传输编码为分块。始终接受没有传输编码的消息。

If the TE field-value is empty or if no TE field is present, then only transfer-coding is chunked. A message with no transfer-coding is always acceptable.

User-Agent

User-Agent 请求头字段包含有关发起请求的用户代理的信息。以下是一般语法:

The User-Agent request-header field contains information about the user agent originating the request. Following is the general syntax:

User-Agent : product | comment

示例:

Example:

User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)

Server Response Headers

Accept-Ranges

Accept-Ranges 响应标头字段允许服务器指示其接受对资源的范围请求。通用语法为:

The Accept-Ranges response-header field allows the server to indicate its acceptance of range requests for a resource. The general syntax is:

Accept-Ranges  : range-unit | none

例如,可以接受字节范围请求的服务器可能会发送:

For example a server that accepts byte-range requests may send:

Accept-Ranges: bytes

不接受任何类型的对某个资源的范围请求的服务器可能发送:

Servers that do not accept any kind of range request for a resource may send:

Accept-Ranges: none

这将建议客户端不要尝试范围请求。

This will advise the client not to attempt a range request.

Age

Age 响应标头字段传达了发件人对从生成服务器生成响应(或其重新验证)以来经过的时间的估计。通用语法为:

The Age response-header field conveys the sender’s estimate of the amount of time since the response (or its revalidation) was generated at the origin server. The general syntax is:

Age : delta-seconds

Age 值是非负十进制整数,代表以秒为单位的时间。以下是一个简单的示例:

Age values are non-negative decimal integers, representing time in seconds. Following is a simple example:

Age: 1030

包含缓存的 HTTP/1.1 服务器必须在从其自身缓存生成的每个响应中包含一个 Age 头字段。

An HTTP/1.1 server that includes a cache must include an Age header field in every response generated from its own cache.

ETag

ETag 响应标头字段提供所请求变体的实体标记的当前值。通用语法为:

The ETag response-header field provides the current value of the entity tag for the requested variant. The general syntax is:

ETag :  entity-tag

这里有一些简单的示例:

Here are some simple examples:

ETag: "xyzzy"
ETag: W/"xyzzy"
ETag: ""

Location

Location 响应标头字段用于将接收器重定向到 Request-URI 以外的位置以完成操作。通用语法为:

The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion. The general syntax is:

Location : absoluteURI

以下是一个简单的示例:

Following is a simple example:

Location: http://www.tutorialspoint.org/http/index.htm

Content-Location 头字段与 Location 不同,因为 Content-Location 标识请求中包含的实体的原始位置。

The Content-Location header field differs from Location in that the Content-Location identifies the original location of the entity enclosed in the request.

Proxy-Authenticate

Proxy-Authenticate 响应标头字段必须包含在 407(需要代理身份验证)响应中。通用语法为:

The Proxy-Authenticate response-header field must be included as a part of a 407 (Proxy Authentication Required) response. The general syntax is:

Proxy-Authenticate  : challenge

Retry-After

Retry-After 响应标头字段可与 503(服务不可用)响应一起使用,以指示预计服务对请求客户端不可用的时间。通用语法为:

The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client. The general syntax is:

Retry-After : HTTP-date | delta-seconds

示例:

Examples:

Retry-After: Fri, 31 Dec 1999 23:59:59 GMT
Retry-After: 120

在后一个示例中,延迟为 2 分钟。

In the latter example, the delay is 2 minutes.

Server

Server 响应标头字段包含原服务器用来处理请求的软件信息。通用语法为:

The Server response-header field contains information about the software used by the origin server to handle the request. The general syntax is:

Server : product | comment

以下是一个简单的示例:

Following is a simple example:

Server: Apache/2.2.14 (Win32)

如果响应通过代理转发,代理应用程序不得修改服务器响应头。

If the response is being forwarded through a proxy, the proxy application must not modify the Server response-header.

Set-Cookie 响应标头字段包含要为此 URL 保留的键/值信息对。通用语法为:

The Set-Cookie response-header field contains a name/value pair of information to retain for this URL. The general syntax is:

Set-Cookie: NAME=VALUE; OPTIONS

Set-Cookie 响应头部包括 Set-Cookie 令牌,后跟由一个或多个 Cookie 组成的用逗号分隔的列表。这里是可以指定为选项的可能值:

Set-Cookie response header comprises the token Set-Cookie, followed by a comma-separated list of one or more cookies. Here are the possible values you can specify as options:

S.N.

Options and Description

1

*Comment=comment*This option can be used to specify any comment associated with the cookie.

2

* Domain=domain*The Domain attribute specifies the domain for which the cookie is valid.

3

*Expires=Date-time*The date the cookie will expire. If it is blank, the cookie will expire when the visitor quits the browser.

4

* Path=path*The Path attribute specifies the subset of URLs to which this cookie applies.

5

*Secure*It instructs the user agent to return the cookie only under a secure connection.

以下是服务器生成的一个简单 Cookie 头的示例:

Following is an example of a simple cookie header generated by the server:

Set-Cookie: name1=value1,name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT

Vary

Vary响应头字段指定该实体有多个来源,因此可能会根据请求头部的指定列表而变化。以下是通用语法:

The Vary response-header field specifies that the entity has multiple sources and may therefore vary according to the specified list of request header(s). Following is the general syntax:

Vary : field-name

您可以指定多个由逗号分隔的标头,星号"*"表示未指定的参数不限于请求标头。以下是简单的示例:

You can specify multiple headers separated by commas and a value of asterisk "*" signals that unspecified parameters are not limited to the request-headers. Following is a simple example:

Vary: Accept-Language, Accept-Encoding

此处字段名不区分大小写。

Here field names are case-insensitive.

WWW-Authenticate

WWW-Authenticate响应头字段必须包含在401(未授权)响应消息中。字段值包含至少一个质询,指示适用于Request-URI的身份验证方案和参数。通用语法为:

The WWW-Authenticate response-header field must be included in 401 (Unauthorized) response messages. The field value consists of at least one challenge that indicates the authentication scheme(s) and parameters applicable to the Request-URI. The general syntax is:

WWW-Authenticate : challenge

WWW-Authenticate字段值可能包含多个质询,或者如果提供了多个WWW-Authenticate头部字段,则质询本身的内容可能包含以逗号分隔的身份验证参数列表。以下是一个简单的例子:

WWW- Authenticate field value might contain more than one challenge, or if more than one WWW-Authenticate header field is provided, the contents of a challenge itself can contain a comma-separated list of authentication parameters. Following is a simple example:

WWW-Authenticate: BASIC realm="Admin"

Entity Headers

Allow

Allow实体头部字段列出了请求URI标识的资源支持的方法集。通用语法为:

The Allow entity-header field lists the set of methods supported by the resource identified by the Request-URI. The general syntax is:

Allow : Method

您可以指定多个由逗号分隔的方法。以下是一个简单的例子:

You can specify multiple methods separated by commas. Following is a simple example:

Allow: GET, HEAD, PUT

此字段不能防止客户端尝试其他方法。

This field cannot prevent a client from trying other methods.

Content-Encoding

Content-Encoding实体头字段用作媒体类型的修饰符。通用语法为:

The Content-Encoding entity-header field is used as a modifier to the media-type. The general syntax is:

Content-Encoding : content-coding

内容编码是请求 URI 标识的实体的一个特征。以下是一个简单的示例:

The content-coding is a characteristic of the entity identified by the Request-URI. Following is a simple example:

Content-Encoding: gzip

如果请求消息中实体的内容编码对原始服务器不可接受,则服务器应以 415(不支持的媒体类型)状态代码进行响应。

If the content-coding of an entity in a request message is not acceptable to the origin server, the server should respond with a status code of 415 (Unsupported Media Type).

Content-Language

Content-Language 实体首字段描述了所附实体的预期受众的自然语言。以下是其通用语法:

The Content-Language entity-header field describes the natural language(s) of the intended audience for the enclosed entity. Following is the general syntax:

Content-Language : language-tag

针对多个受众的内容可能会列出多种语言。以下是一个简单的示例:

Multiple languages may be listed for content that is intended for multiple audiences. Following is a simple example:

Content-Language: mi, en

Content-Language 的主要目的是允许用户根据自己的首选语言识别和区分实体。

The primary purpose of Content-Language is to allow a user to identify and differentiate entities according to the user’s own preferred language.

Content-Length

Content-Length实体头字段指示发送给接收方的实体主体的大小(以八位字节为十进制数),或者对于HEAD方法,指示如果请求是GET,则本来会发送的实体主体的尺寸。通用语法为:

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent, had the request been a GET. The general syntax is:

Content-Length : DIGITS

以下是一个简单的示例:

Following is a simple example:

Content-Length: 3495

任何大于或等于零的内容长度都是一个有效值。

Any Content-Length greater than or equal to zero is a valid value.

Content-Location

当实体可以通过与请求资源URI分开的地址访问时,Content-Location实体头部字段可以用于提供消息中包含的实体的资源位置。通用语法为:

The Content-Location entity-header field may be used to supply the resource location for the entity enclosed in the message when that entity is accessible from a location separate from the requested resource’s URI. The general syntax is:

Content-Location:  absoluteURI | relativeURI

以下是一个简单的示例:

Following is a simple example:

Content-Location: http://www.tutorialspoint.org/http/index.htm

Content-Location 的值也定义了该实体的基 URI。

The value of Content-Location also defines the base URI for the entity.

Content-MD5

Content-MD5实体头字段可用于提供接收后检查消息完整性的实体的MD5摘要。通用语法为:

The Content-MD5 entity-header field may be used to supply an MD5 digest of the entity for checking the integrity of the message upon receipt. The general syntax is:

Content-MD5  : md5-digest using base64 of 128 bit MD5 digest as per RFC 1864

以下是一个简单的示例:

Following is a simple example:

Content-MD5  : 8c2d46911f3f5a326455f0ed7a8ed3b3

MD5 摘要基于实体体的内容(包括已应用的所有内容编码)计算得出,但不包括对消息体应用的传输编码。

The MD5 digest is computed based on the content of the entity-body, including any content-coding that has been applied, but not including any transfer-encoding applied to the message-body.

Content-Range

Content-Range实体头字段与部分实体主体一起发送,以指定应在完整实体主体中应用部分实体主体的位置。通用语法为:

The Content-Range entity-header field is sent with a partial entity-body to specify where in the full entity-body the partial body should be applied. The general syntax is:

Content-Range : bytes-unit SP first-byte-pos "-" last-byte-pos

假设该实体总共包含 1234 个字节,下面给出 byte-content-range-spec 值的示例:

Examples of byte-content-range-spec values, assuming that the entity contains a total of 1234 bytes:

- The first 500 bytes:
Content-Range : bytes 0-499/1234

- The second 500 bytes:
Content-Range : bytes 500-999/1234

- All except for the first 500 bytes:
Content-Range : bytes 500-1233/1234

- The last 500 bytes:
Content-Range : bytes 734-1233/1234

当一条 HTTP 消息包括一个单一范围的内容时,此内容会随 Content-Range 头一同传输,且 Content-Length 头显示实际传输的字节数。例如,

When an HTTP message includes the content of a single range, this content is transmitted with a Content-Range header, and a Content-Length header showing the number of bytes actually transferred. For example,

HTTP/1.1 206 Partial content
Date: Wed, 15 Nov 1995 06:25:24 GMT
Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT
Content-Range: bytes 21010-47021/47022
Content-Length: 26012
Content-Type: image/gif

Content-Type

Content-Type实体头字段指示发送到接收方的实体主体的媒体类型,或者对于HEAD方法,指示如果请求是GET,则本来会发送的媒体类型。通用语法为:

The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent, had the request been a GET. The general syntax is:

Content-Type : media-type

下面是一个示例:

Following is an example:

Content-Type: text/html; charset=ISO-8859-4

Expires

Expires实体头字段指定响应被视为过时的日期/时间。通用语法为:

The Expires entity-header field gives the date/time after which the response is considered stale. The general syntax is:

Expires : HTTP-date

下面是一个示例:

Following is an example:

Expires: Thu, 01 Dec 1994 16:00:00 GMT

Last-Modified

Last-Modified实体头字段指示原始服务器认为该变体最后修改的日期和时间。通用语法为:

The Last-Modified entity-header field indicates the date and time at which the origin server believes the variant was last modified. The general syntax is:

Last-Modified: HTTP-date

下面是一个示例:

Following is an example:

Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT