8 | 8 |
#include <ngx_http.h>
|
9 | 9 |
|
10 | 10 |
|
11 | |
|
|
11 |
static ngx_int_t ngx_http_test_precondition(ngx_http_request_t *r);
|
|
12 |
static ngx_int_t ngx_http_test_not_modified(ngx_http_request_t *r);
|
12 | 13 |
static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf);
|
13 | 14 |
|
14 | 15 |
|
|
49 | 50 |
static ngx_int_t
|
50 | 51 |
ngx_http_not_modified_header_filter(ngx_http_request_t *r)
|
51 | 52 |
{
|
52 | |
time_t ims;
|
53 | |
ngx_http_core_loc_conf_t *clcf;
|
54 | |
|
55 | 53 |
if (r->headers_out.status != NGX_HTTP_OK
|
56 | 54 |
|| r != r->main
|
57 | |
|| r->headers_in.if_modified_since == NULL
|
58 | 55 |
|| r->headers_out.last_modified_time == -1)
|
59 | 56 |
{
|
60 | 57 |
return ngx_http_next_header_filter(r);
|
61 | 58 |
}
|
|
59 |
|
|
60 |
if (r->headers_in.if_unmodified_since) {
|
|
61 |
return ngx_http_test_precondition(r);
|
|
62 |
}
|
|
63 |
|
|
64 |
if (r->headers_in.if_modified_since) {
|
|
65 |
return ngx_http_test_not_modified(r);
|
|
66 |
}
|
|
67 |
|
|
68 |
return ngx_http_next_header_filter(r);
|
|
69 |
}
|
|
70 |
|
|
71 |
|
|
72 |
static ngx_int_t
|
|
73 |
ngx_http_test_precondition(ngx_http_request_t *r)
|
|
74 |
{
|
|
75 |
time_t iums;
|
|
76 |
|
|
77 |
iums = ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data,
|
|
78 |
r->headers_in.if_unmodified_since->value.len);
|
|
79 |
|
|
80 |
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
81 |
"http iums:%d lm:%d", iums, r->headers_out.last_modified_time);
|
|
82 |
|
|
83 |
if (iums >= r->headers_out.last_modified_time) {
|
|
84 |
return ngx_http_next_header_filter(r);
|
|
85 |
}
|
|
86 |
|
|
87 |
return ngx_http_filter_finalize_request(r, NULL,
|
|
88 |
NGX_HTTP_PRECONDITION_FAILED);
|
|
89 |
}
|
|
90 |
|
|
91 |
|
|
92 |
static ngx_int_t
|
|
93 |
ngx_http_test_not_modified(ngx_http_request_t *r)
|
|
94 |
{
|
|
95 |
time_t ims;
|
|
96 |
ngx_http_core_loc_conf_t *clcf;
|
62 | 97 |
|
63 | 98 |
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
64 | 99 |
|