comparison src/http/modules/ngx_http_not_modified_filter_module.c @ 608:3036c1836a24 NGINX_0_9_2

nginx 0.9.2 *) Feature: the "If-Unmodified-Since" client request header line support. *) Workaround: fallback to accept() syscall if accept4() was not implemented; the issue had appeared in 0.9.0. *) Bugfix: nginx could not be built on Cygwin; the issue had appeared in 0.9.0. *) Bugfix: for OpenSSL vulnerability CVE-2010-4180. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Mon, 06 Dec 2010 00:00:00 +0300
parents 40c366b3535c
children ce857f6b74a7
comparison
equal deleted inserted replaced
607:a87726a9033b 608:3036c1836a24
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);