Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_not_modified_filter_module.c @ 5118:af155fc41deb
Image filter: the "image_filter_interlace" directive.
Patch by Ian Babrou, with minor changes.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 19 Mar 2013 08:13:48 +0000 |
parents | 5b93a9ac60ed |
children | bb3d74fc4aea |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
6 |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
13 static ngx_uint_t ngx_http_test_if_unmodified(ngx_http_request_t *r); |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
14 static ngx_uint_t ngx_http_test_if_modified(ngx_http_request_t *r); |
4744
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
15 static ngx_uint_t ngx_http_test_if_match(ngx_http_request_t *r, |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
16 ngx_table_elt_t *header); |
681 | 17 static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf); |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = { |
509 | 21 NULL, /* preconfiguration */ |
681 | 22 ngx_http_not_modified_filter_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
23 |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 NULL, /* create main configuration */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 NULL, /* init main configuration */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 NULL, /* create server configuration */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 NULL, /* merge server configuration */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 NULL, /* create location configuration */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 NULL /* merge location configuration */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 }; |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 ngx_module_t ngx_http_not_modified_filter_module = { |
509 | 36 NGX_MODULE_V1, |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 &ngx_http_not_modified_filter_module_ctx, /* module context */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 NULL, /* module directives */ |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 NGX_HTTP_MODULE, /* module type */ |
541 | 40 NULL, /* init master */ |
681 | 41 NULL, /* init module */ |
541 | 42 NULL, /* init process */ |
43 NULL, /* init thread */ | |
44 NULL, /* exit thread */ | |
45 NULL, /* exit process */ | |
46 NULL, /* exit master */ | |
47 NGX_MODULE_V1_PADDING | |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 }; |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
51 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
2702 | 54 static ngx_int_t |
55 ngx_http_not_modified_header_filter(ngx_http_request_t *r) | |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 { |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 if (r->headers_out.status != NGX_HTTP_OK |
597 | 58 || r != r->main |
142
cb77c084acdb
nginx-0.0.1-2003-10-09-11:00:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
59 || r->headers_out.last_modified_time == -1) |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
61 return ngx_http_next_header_filter(r); |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 } |
3854
80cc7c8bb845
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
3814
diff
changeset
|
63 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
64 if (r->headers_in.if_unmodified_since |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
65 && !ngx_http_test_if_unmodified(r)) |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
66 { |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
67 return ngx_http_filter_finalize_request(r, NULL, |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
68 NGX_HTTP_PRECONDITION_FAILED); |
3814
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
69 } |
3854
80cc7c8bb845
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
3814
diff
changeset
|
70 |
4744
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
71 if (r->headers_in.if_match |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
72 && !ngx_http_test_if_match(r, r->headers_in.if_match)) |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
73 { |
4744
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
74 return ngx_http_filter_finalize_request(r, NULL, |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
75 NGX_HTTP_PRECONDITION_FAILED); |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
76 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
77 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
78 if (r->headers_in.if_modified_since || r->headers_in.if_none_match) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
79 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
80 if (r->headers_in.if_modified_since |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
81 && ngx_http_test_if_modified(r)) |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
82 { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
83 return ngx_http_next_header_filter(r); |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
84 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
85 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
86 if (r->headers_in.if_none_match |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
87 && !ngx_http_test_if_match(r, r->headers_in.if_none_match)) |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
88 { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
89 return ngx_http_next_header_filter(r); |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
90 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
91 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
92 /* not modified */ |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
93 |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
94 r->headers_out.status = NGX_HTTP_NOT_MODIFIED; |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
95 r->headers_out.status_line.len = 0; |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
96 r->headers_out.content_type.len = 0; |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
97 ngx_http_clear_content_length(r); |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
98 ngx_http_clear_accept_ranges(r); |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
99 |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
100 if (r->headers_out.content_encoding) { |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
101 r->headers_out.content_encoding->hash = 0; |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
102 r->headers_out.content_encoding = NULL; |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
103 } |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
104 |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
105 return ngx_http_next_header_filter(r); |
3814
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
106 } |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
107 |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
108 return ngx_http_next_header_filter(r); |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
109 } |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
110 |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
111 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
112 static ngx_uint_t |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
113 ngx_http_test_if_unmodified(ngx_http_request_t *r) |
3814
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
114 { |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
115 time_t iums; |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
116 |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
117 iums = ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data, |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
118 r->headers_in.if_unmodified_since->value.len); |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
119 |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
120 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
121 "http iums:%d lm:%d", iums, r->headers_out.last_modified_time); |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
122 |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
123 if (iums >= r->headers_out.last_modified_time) { |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
124 return 1; |
3814
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
125 } |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
126 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
127 return 0; |
3814
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
128 } |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
129 |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
130 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
131 static ngx_uint_t |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
132 ngx_http_test_if_modified(ngx_http_request_t *r) |
3814
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
133 { |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
134 time_t ims; |
e6e453203bae
"If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents:
3308
diff
changeset
|
135 ngx_http_core_loc_conf_t *clcf; |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 |
2496 | 137 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
138 | |
139 if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) { | |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
140 return 1; |
2496 | 141 } |
142 | |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data, |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 r->headers_in.if_modified_since->value.len); |
577 | 145 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
146 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
147 "http ims:%d lm:%d", ims, r->headers_out.last_modified_time); |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
149 if (ims == r->headers_out.last_modified_time) { |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
150 return 0; |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 } |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
153 if (clcf->if_modified_since == NGX_HTTP_IMS_EXACT |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
154 || ims < r->headers_out.last_modified_time) |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
155 { |
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
156 return 1; |
3308
793ae4dd91e9
remove "Content-Encoding: gzip" in 304 response
Igor Sysoev <igor@sysoev.ru>
parents:
2702
diff
changeset
|
157 } |
793ae4dd91e9
remove "Content-Encoding: gzip" in 304 response
Igor Sysoev <igor@sysoev.ru>
parents:
2702
diff
changeset
|
158 |
4743
84cc73e01aa8
Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
159 return 0; |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 } |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 |
4744
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
163 static ngx_uint_t |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
164 ngx_http_test_if_match(ngx_http_request_t *r, ngx_table_elt_t *header) |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
165 { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
166 u_char *start, *end, ch; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
167 ngx_str_t *etag, *list; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
168 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
169 list = &header->value; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
170 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
171 if (list->len == 1 && list->data[0] == '*') { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
172 return 1; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
173 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
174 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
175 if (r->headers_out.etag == NULL) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
176 return 0; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
177 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
178 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
179 etag = &r->headers_out.etag->value; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
180 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
181 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
182 "http im:\"%V\" etag:%V", list, etag); |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
183 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
184 start = list->data; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
185 end = list->data + list->len; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
186 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
187 while (start < end) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
188 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
189 if (etag->len > (size_t) (end - start)) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
190 return 0; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
191 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
192 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
193 if (ngx_strncmp(start, etag->data, etag->len) != 0) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
194 goto skip; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
195 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
196 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
197 start += etag->len; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
198 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
199 while (start < end) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
200 ch = *start; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
201 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
202 if (ch == ' ' || ch == '\t') { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
203 start++; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
204 continue; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
205 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
206 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
207 break; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
208 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
209 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
210 if (start == end || *start == ',') { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
211 return 1; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
212 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
213 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
214 skip: |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
215 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
216 while (start < end && *start != ',') { start++; } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
217 while (start < end) { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
218 ch = *start; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
219 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
220 if (ch == ' ' || ch == '\t' || ch == ',') { |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
221 start++; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
222 continue; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
223 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
224 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
225 break; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
226 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
227 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
228 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
229 return 0; |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
230 } |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
231 |
5b93a9ac60ed
Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4743
diff
changeset
|
232 |
2702 | 233 static ngx_int_t |
234 ngx_http_not_modified_filter_init(ngx_conf_t *cf) | |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
235 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
236 ngx_http_next_header_filter = ngx_http_top_header_filter; |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
237 ngx_http_top_header_filter = ngx_http_not_modified_header_filter; |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
238 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 return NGX_OK; |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 } |