Cache: ETag now saved into cache header.
This commit is contained in:
parent
3e0eecc7a1
commit
b393276eee
|
@ -24,8 +24,9 @@
|
|||
#define NGX_HTTP_CACHE_SCARCE 8
|
||||
|
||||
#define NGX_HTTP_CACHE_KEY_LEN 16
|
||||
#define NGX_HTTP_CACHE_ETAG_LEN 42
|
||||
|
||||
#define NGX_HTTP_CACHE_VERSION 1
|
||||
#define NGX_HTTP_CACHE_VERSION 2
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
@ -69,6 +70,8 @@ struct ngx_http_cache_s {
|
|||
time_t last_modified;
|
||||
time_t date;
|
||||
|
||||
ngx_str_t etag;
|
||||
|
||||
size_t header_start;
|
||||
size_t body_start;
|
||||
off_t length;
|
||||
|
@ -107,6 +110,8 @@ typedef struct {
|
|||
u_short valid_msec;
|
||||
u_short header_start;
|
||||
u_short body_start;
|
||||
u_char etag_len;
|
||||
u_char etag[NGX_HTTP_CACHE_ETAG_LEN];
|
||||
} ngx_http_file_cache_header_t;
|
||||
|
||||
|
||||
|
|
|
@ -525,6 +525,8 @@ ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c)
|
|||
c->valid_msec = h->valid_msec;
|
||||
c->header_start = h->header_start;
|
||||
c->body_start = h->body_start;
|
||||
c->etag.len = h->etag_len;
|
||||
c->etag.data = h->etag;
|
||||
|
||||
r->cached = 1;
|
||||
|
||||
|
@ -890,6 +892,11 @@ ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf)
|
|||
h->header_start = (u_short) c->header_start;
|
||||
h->body_start = (u_short) c->body_start;
|
||||
|
||||
if (c->etag.len <= NGX_HTTP_CACHE_ETAG_LEN) {
|
||||
h->etag_len = (u_char) c->etag.len;
|
||||
ngx_memcpy(h->etag, c->etag.data, c->etag.len);
|
||||
}
|
||||
|
||||
p = buf + sizeof(ngx_http_file_cache_header_t);
|
||||
|
||||
p = ngx_cpymem(p, ngx_http_file_cache_key, sizeof(ngx_http_file_cache_key));
|
||||
|
@ -1077,6 +1084,11 @@ ngx_http_file_cache_update_header(ngx_http_request_t *r)
|
|||
h.header_start = (u_short) c->header_start;
|
||||
h.body_start = (u_short) c->body_start;
|
||||
|
||||
if (c->etag.len <= NGX_HTTP_CACHE_ETAG_LEN) {
|
||||
h.etag_len = (u_char) c->etag.len;
|
||||
ngx_memcpy(h.etag, c->etag.data, c->etag.len);
|
||||
}
|
||||
|
||||
(void) ngx_write_file(&file, (u_char *) &h,
|
||||
sizeof(ngx_http_file_cache_header_t), 0);
|
||||
|
||||
|
|
|
@ -2498,6 +2498,10 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||
r->cache->date = now;
|
||||
r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start);
|
||||
|
||||
if (u->headers_in.etag) {
|
||||
r->cache->etag = u->headers_in.etag->value;
|
||||
}
|
||||
|
||||
ngx_http_file_cache_set_header(r, u->buffer.start);
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue