In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how the etag in nginx is generated". In the daily operation, I believe that many people have doubts about how the etag in nginx is generated. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how is the etag in nginx generated?" Next, please follow the editor to study!
Generation of ETag in nginx
I found some information and source code on the Internet to learn about the calculation method of etag. Represented by python pseudo code, the calculation method is as follows
Etag ='{: X}-{: X} '.format (header.last_modified, header.content_lenth)
Source code: ngx_http_core_modules.c [2]
Etag- > value.len = ngx_sprintf (etag- > value.data, "\"% xT-%xO\ ""
R-> headers_out.last_modified_time
R-> headers_out.content_length_n)
-etag- > value.data
Summary: etag in nginx consists of a combination of Last-Modified and Content-Length in the response header as hexadecimal.
Find a nginx service in my K8s cluster to test it.
$curl-- head 10.97.109.49
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Tue, 10 Dec 2019 06:45:24 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 23 Apr 2019 10:18:21 GMT
Connection: keep-alive
ETag: "5cbee66d-264"
Accept-Ranges: bytes
Last-Modified and Content-Length are calculated by etag and calculated using js as follows. The results are consistent.
> new Date (parseInt ('5cbee66dink, 16) * 1000). ToJSON ()
2019-04-23T10:18:21.000Z
> parseInt ('264 years, 16)
612 Last-Modified,ETag and negotiation caching
We know that there are two ways to negotiate caching
Last-Modified/ if-Modified-SinceETag/ If-None-Match
Since ETag is made up of Last-Modified and Content-Length in nginx, it can be regarded as an enhanced version of Last-Modified, so where is the enhancement?
* * Last-Modified is represented by a unix timestamp, which means that it can only act on changes in seconds * *
Then the next question: if the ETag value in the http response header has changed, does it mean that the content of the file must have changed [3]
At this point, the study on "how the etag in nginx is generated" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.