Klaus Demo nginx / ec4df83
"If-Unmodified-Since" support Igor Sysoev 9 years ago
3 changed file(s) with 45 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
88 #include <ngx_http.h>
99
1010
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);
1213 static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf);
1314
1415
4950 static ngx_int_t
5051 ngx_http_not_modified_header_filter(ngx_http_request_t *r)
5152 {
52 time_t ims;
53 ngx_http_core_loc_conf_t *clcf;
54
5553 if (r->headers_out.status != NGX_HTTP_OK
5654 || r != r->main
57 || r->headers_in.if_modified_since == NULL
5855 || r->headers_out.last_modified_time == -1)
5956 {
6057 return ngx_http_next_header_filter(r);
6158 }
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;
6297
6398 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
6499
8585
8686 { ngx_string("If-Modified-Since"),
8787 offsetof(ngx_http_headers_in_t, if_modified_since),
88 ngx_http_process_unique_header_line },
89
90 { ngx_string("If-Unmodified-Since"),
91 offsetof(ngx_http_headers_in_t, if_unmodified_since),
8892 ngx_http_process_unique_header_line },
8993
9094 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent),
166166 ngx_table_elt_t *host;
167167 ngx_table_elt_t *connection;
168168 ngx_table_elt_t *if_modified_since;
169 ngx_table_elt_t *if_unmodified_since;
169170 ngx_table_elt_t *user_agent;
170171 ngx_table_elt_t *referer;
171172 ngx_table_elt_t *content_length;