-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第 157 题:浏览器缓存 ETag 里的值是怎么生成的 #383
Comments
Etag是服务器响应请求时,返回当前资源文件的一个唯一标识(由服务器生成)。
'W/'(大小写敏感) |
1. Nginx 的 ETag 生成方式:http://lxr.nginx.org/source/src/http/ngx_http_core_module.c注意:行1608、1609 1581 ngx_int_t
1582 ngx_http_set_etag(ngx_http_request_t *r)
1583 {
1584 ngx_table_elt_t *etag;
1585 ngx_http_core_loc_conf_t *clcf;
1586
1587 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1588
1589 if (!clcf->etag) {
1590 return NGX_OK;
1591 }
1592
1593 etag = ngx_list_push(&r->headers_out.headers);
1594 if (etag == NULL) {
1595 return NGX_ERROR;
1596 }
1597
1598 etag->hash = 1;
1599 ngx_str_set(&etag->key, "ETag");
1600
1601 etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
1602 if (etag->value.data == NULL) {
1603 etag->hash = 0;
1604 return NGX_ERROR;
1605 }
1606
1607 etag->value.len = ngx_sprintf(etag->value.data, "\"%xT-%xO\"",
1608 r->headers_out.last_modified_time,
1609 r->headers_out.content_length_n)
1610 - etag->value.data;
1611
1612 r->headers_out.etag = etag;
1613
1614 return NGX_OK;
1615 } 2. Apache 的生成方式 http://httpd.apache.org/docs/2.2/mod/core.html#fileetag关于配置里提到的 inode,不知道的可以参考:http://www.ruanyifeng.com/blog/2011/12/inode.html 不同 Web 服务器或者 CDN 的 ETag 生成方式可能不一样。 |
Etag 是一个文件变换就要重新生成的一个值,如果用hash来计算达不到效率 |
No description provided.
The text was updated successfully, but these errors were encountered: