annuaire recherche
Guides Access control CORS Authentication Browser detection using the user agent Caching Caching FAQ Compression Conditional requests Connection management in HTTP 1.x Content negotiation Content negotiation: List of default Accept values Cookies CSP Messages Overview Protocol upgrade mechanism Proxy servers and tunneling Proxy servers and tunneling: Proxy Auto-Configuration (PAC) file Public Key Pinning Range requests Redirections Resources and specifications Resources and URIs Response codes Server-Side Access Control Session Guides: Basics Basics of HTTP Choosing between www and non-www URLs Data URIs Evolution of HTTP Identifying resources on the Web MIME Types MIME types: Complete list of MIME types CSP Content-Security-Policy Content-Security-Policy-Report-Only CSP: base-uri CSP: block-all-mixed-content CSP: child-src CSP: connect-src CSP: default-src CSP: font-src CSP: form-action CSP: frame-ancestors CSP: frame-src CSP: img-src CSP: manifest-src CSP: media-src CSP: object-src CSP: plugin-types CSP: referrer CSP: report-uri CSP: require-sri-for CSP: sandbox CSP: script-src CSP: style-src CSP: upgrade-insecure-requests CSP: worker-src Headers Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges Access-Control-Allow-Credentials Access-Control-Allow-Headers Access-Control-Allow-Methods Access-Control-Allow-Origin Access-Control-Expose-Headers Access-Control-Max-Age Access-Control-Request-Headers Access-Control-Request-Method Age Allow Authorization Cache-Control Connection Content-Disposition Content-Encoding Content-Language Content-Length Content-Location Content-Range Content-Type Cookie Cookie2 Date DNT ETag Expect Expires Forwarded From Headers Host If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since Keep-Alive Large-Allocation Last-Modified Location Origin Pragma Proxy-Authenticate Proxy-Authorization Public-Key-Pins Public-Key-Pins-Report-Only Range Referer Referrer-Policy Retry-After Server Set-Cookie Set-Cookie2 SourceMap Strict-Transport-Security TE Tk Trailer Transfer-Encoding Upgrade-Insecure-Requests User-Agent User-Agent: Firefox Vary Via Warning WWW-Authenticate X-Content-Type-Options X-DNS-Prefetch-Control X-Forwarded-For X-Forwarded-Host X-Forwarded-Proto X-Frame-Options X-XSS-Protection Methods CONNECT DELETE GET HEAD Methods OPTIONS PATCH POST PUT Status 100 Continue 101 Switching Protocols 200 OK 201 Created 202 Accepted 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 300 Multiple Choices 301 Moved Permanently 302 Found 303 See Other 304 Not Modified 307 Temporary Redirect 308 Permanent Redirect 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Payload Too Large 414 URI Too Long 415 Unsupported Media Type 416 Range Not Satisfiable 417 Expectation Failed 426 Upgrade Required 428 Precondition Required 429 Too Many Requests 431 Request Header Fields Too Large 451 Unavailable For Legal Reasons 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported 511 Network Authentication Required Status
personnages

所述ETag HTTP 响应报头为资源的特定版本的标识符。它允许缓存更高效,并节省带宽,因为如果内容没有改变,Web 服务器不需要发送完整的响应。另一方面,如果内容发生了变化,etags 有助于防止资源的同时更新互相覆盖(“空中冲突”)。

如果给定 URL 处的资源发生更改,则Etag必须生成新值。因此,Etags 与指纹相似,也可能用于某些服务器的跟踪目的。它们的比较可以快速确定资源的两个表示是否相同,但它们也可能被设置为无限期地由跟踪服务器持续存在。

Header type

Response header

Forbidden header name

no

语法

ETag: W/"<etag_value>"ETag: "<etag_value>"

指令

W/可选'W/'(区分大小写)表示使用弱验证程序。弱验证器很容易生成,但对于比较来说却不太有用。强大的验证器是进行比较的理想选择,但可能非常难以高效生成。

Etag相同资源的两个表示的弱值可能在语义上是等价的,但不是字节一致的。“<etag_value>”实体标记唯一地表示请求的资源。它们是放在双引号(像是"675af34563dc-tr34")之间的 ASCII 字符串。

ETag没有指定生成值的方法。通常,使用内容的散列,最后修改时间戳的散列或仅修订版本号。例如,MDN 使用 wiki 内容的十六进制数字的散列。

例子

ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"ETag: W/"0815"

避免空中碰撞

借助标题ETagIf-Match头文件,您可以检测到空中编辑冲突。

例如,在编辑 MDN 时,当前的 wiki 内容被散列并放入Etag响应中:

ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"

当保存对 wiki 页面的更改(发布数据)时,POST请求将包含包含要检查新鲜度If-MatchETag值的标题。

If-Match: "33a64df551425fcc55e4d42a148795d9f25f89d4"

如果散列不匹配,则意味着文档已被编辑,并且412 Precondition Failed引发错误。

缓存不变的资源

ETag标题的另一个典型用例是缓存未更改的资源。如果用户再次访问一个给定的 URL(它有一个ETag集合),并且它已经过时了,那么这个 URL 太旧而不能被视为可用,客户端会将它的值发送到ETag一个If-None-Match标题字段中:

If-None-Match: "33a64df551425fcc55e4d42a148795d9f25f89d4"

服务器比较客户端ETag(与其If-None-Match一起发送)ETag与其当前版本的资源,并且如果两个值匹配(即资源没有改变),则服务器发回304 Not Modified状态,没有任何正文,告诉客户端缓存版本的响应仍然很好用(新鲜)。

规范

Specification

Title

RFC 7232, section 2.3: ETag

Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests

浏览器兼容性

Feature

Chrome

Firefox

Edge

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Article précédent: Article suivant: