annotate src/http/modules/ngx_http_not_modified_filter_module.c @ 7653:8409f9df6219

SSL: client certificate validation with OCSP (ticket #1534). OCSP validation for client certificates is enabled by the "ssl_ocsp" directive. OCSP responder can be optionally specified by "ssl_ocsp_responder". When session is reused, peer chain is not available for validation. If the verified chain contains certificates from the peer chain not available at the server, validation will fail.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 22 May 2020 17:30:12 +0300
parents 8b6fa4842133
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 3854
diff changeset
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,
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
16 ngx_table_elt_t *header, ngx_uint_t weak);
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
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
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
21 NULL, /* preconfiguration */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
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
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
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
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
40 NULL, /* init master */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
41 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
42 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
43 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
44 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
45 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
46 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
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
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
54 static ngx_int_t
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
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
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
58 || r != r->main
5735
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
59 || r->disable_not_modified)
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
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
72 && !ngx_http_test_if_match(r, r->headers_in.if_match, 0))
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
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
87 && !ngx_http_test_if_match(r, r->headers_in.if_none_match, 1))
4744
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
5735
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
117 if (r->headers_out.last_modified_time == (time_t) -1) {
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
118 return 0;
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
119 }
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
120
6180
8b6fa4842133 Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5735
diff changeset
121 iums = ngx_parse_http_time(r->headers_in.if_unmodified_since->value.data,
3814
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
122 r->headers_in.if_unmodified_since->value.len);
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
123
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
124 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
5729
bb3d74fc4aea Not modified filter: debug log format fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4744
diff changeset
125 "http iums:%T lm:%T", iums, r->headers_out.last_modified_time);
3814
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
126
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
127 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
128 return 1;
3814
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 return 0;
3814
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
132 }
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
4743
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
135 static ngx_uint_t
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
136 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
137 {
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
138 time_t ims;
e6e453203bae "If-Unmodified-Since" support
Igor Sysoev <igor@sysoev.ru>
parents: 3308
diff changeset
139 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
140
5735
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
141 if (r->headers_out.last_modified_time == (time_t) -1) {
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
142 return 1;
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
143 }
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5734
diff changeset
144
2496
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
145 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
146
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
147 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
148 return 1;
2496
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
149 }
9081bbdccda1 if_modified_since off
Igor Sysoev <igor@sysoev.ru>
parents: 2361
diff changeset
150
6180
8b6fa4842133 Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5735
diff changeset
151 ims = ngx_parse_http_time(r->headers_in.if_modified_since->value.data,
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 r->headers_in.if_modified_since->value.len);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
153
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 195
diff changeset
154 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
5729
bb3d74fc4aea Not modified filter: debug log format fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4744
diff changeset
155 "http ims:%T lm:%T", 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
156
4743
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
157 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
158 return 0;
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 }
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160
4743
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
161 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
162 || ims < r->headers_out.last_modified_time)
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
163 {
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
164 return 1;
3308
793ae4dd91e9 remove "Content-Encoding: gzip" in 304 response
Igor Sysoev <igor@sysoev.ru>
parents: 2702
diff changeset
165 }
793ae4dd91e9 remove "Content-Encoding: gzip" in 304 response
Igor Sysoev <igor@sysoev.ru>
parents: 2702
diff changeset
166
4743
84cc73e01aa8 Not modified filter: tests separated from actions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
167 return 0;
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 }
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170
4744
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
171 static ngx_uint_t
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
172 ngx_http_test_if_match(ngx_http_request_t *r, ngx_table_elt_t *header,
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
173 ngx_uint_t weak)
4744
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 u_char *start, *end, ch;
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
176 ngx_str_t etag, *list;
4744
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 list = &header->value;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
179
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
180 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
181 return 1;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
182 }
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 if (r->headers_out.etag == NULL) {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
185 return 0;
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
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
188 etag = r->headers_out.etag->value;
4744
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
189
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
190 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
191 "http im:\"%V\" etag:%V", list, &etag);
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
192
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
193 if (weak
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
194 && etag.len > 2
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
195 && etag.data[0] == 'W'
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
196 && etag.data[1] == '/')
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
197 {
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
198 etag.len -= 2;
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
199 etag.data += 2;
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
200 }
4744
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 start = list->data;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
203 end = list->data + list->len;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
204
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
205 while (start < end) {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
206
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
207 if (weak
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
208 && end - start > 2
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
209 && start[0] == 'W'
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
210 && start[1] == '/')
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
211 {
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
212 start += 2;
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
213 }
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
214
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
215 if (etag.len > (size_t) (end - start)) {
4744
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
216 return 0;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
217 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
218
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
219 if (ngx_strncmp(start, etag.data, etag.len) != 0) {
4744
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
220 goto skip;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
221 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
222
5734
af229f8cf987 Entity tags: weak comparison for If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5729
diff changeset
223 start += etag.len;
4744
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 while (start < end) {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
226 ch = *start;
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 if (ch == ' ' || ch == '\t') {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
229 start++;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
230 continue;
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
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
233 break;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
234 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
235
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
236 if (start == end || *start == ',') {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
237 return 1;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
238 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
239
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
240 skip:
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
241
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
242 while (start < end && *start != ',') { start++; }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
243 while (start < end) {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
244 ch = *start;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
245
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
246 if (ch == ' ' || ch == '\t' || ch == ',') {
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
247 start++;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
248 continue;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
249 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
250
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
251 break;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
252 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
253 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
254
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
255 return 0;
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
256 }
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
257
5b93a9ac60ed Entity tags: basic support in not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4743
diff changeset
258
2702
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
259 static ngx_int_t
eace65d6092b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2592
diff changeset
260 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
261 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
262 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
263 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
264
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 return NGX_OK;
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 }