Mercurial > hg > nginx
comparison src/http/modules/ngx_http_not_modified_filter_module.c @ 3814:e6e453203bae
"If-Unmodified-Since" support
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 06 Dec 2010 11:11:05 +0000 |
parents | 793ae4dd91e9 |
children | 80cc7c8bb845 |
comparison
equal
deleted
inserted
replaced
3813:c870fb78550c | 3814:e6e453203bae |
---|---|
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 | 10 |
11 | 11 |
12 | 12 static ngx_int_t ngx_http_test_precondition(ngx_http_request_t *r); |
13 static ngx_int_t ngx_http_test_not_modified(ngx_http_request_t *r); | |
13 static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf); | 14 static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf); |
14 | 15 |
15 | 16 |
16 static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = { | 17 static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = { |
17 NULL, /* preconfiguration */ | 18 NULL, /* preconfiguration */ |
48 | 49 |
49 | 50 |
50 static ngx_int_t | 51 static ngx_int_t |
51 ngx_http_not_modified_header_filter(ngx_http_request_t *r) | 52 ngx_http_not_modified_header_filter(ngx_http_request_t *r) |
52 { | 53 { |
53 time_t ims; | |
54 ngx_http_core_loc_conf_t *clcf; | |
55 | |
56 if (r->headers_out.status != NGX_HTTP_OK | 54 if (r->headers_out.status != NGX_HTTP_OK |
57 || r != r->main | 55 || r != r->main |
58 || r->headers_in.if_modified_since == NULL | |
59 || r->headers_out.last_modified_time == -1) | 56 || r->headers_out.last_modified_time == -1) |
60 { | 57 { |
61 return ngx_http_next_header_filter(r); | 58 return ngx_http_next_header_filter(r); |
62 } | 59 } |
60 | |
61 if (r->headers_in.if_unmodified_since) { | |
62 return ngx_http_test_precondition(r); | |
63 } | |
64 | |
65 if (r->headers_in.if_modified_since) { | |
66 return ngx_http_test_not_modified(r); | |
67 } | |
68 | |
69 return ngx_http_next_header_filter(r); | |
70 } | |
71 | |
72 | |
73 static ngx_int_t | |
74 ngx_http_test_precondition(ngx_http_request_t *r) | |
75 { | |
76 time_t iums; | |
77 | |
78 iums = ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data, | |
79 r->headers_in.if_unmodified_since->value.len); | |
80 | |
81 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
82 "http iums:%d lm:%d", iums, r->headers_out.last_modified_time); | |
83 | |
84 if (iums >= r->headers_out.last_modified_time) { | |
85 return ngx_http_next_header_filter(r); | |
86 } | |
87 | |
88 return ngx_http_filter_finalize_request(r, NULL, | |
89 NGX_HTTP_PRECONDITION_FAILED); | |
90 } | |
91 | |
92 | |
93 static ngx_int_t | |
94 ngx_http_test_not_modified(ngx_http_request_t *r) | |
95 { | |
96 time_t ims; | |
97 ngx_http_core_loc_conf_t *clcf; | |
63 | 98 |
64 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 99 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
65 | 100 |
66 if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) { | 101 if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) { |
67 return ngx_http_next_header_filter(r); | 102 return ngx_http_next_header_filter(r); |