Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_static_module.c @ 8842:dd718d1cef3c
Cache: fixed race in ngx_http_file_cache_forced_expire().
During configuration reload two cache managers might exist for a short
time. If both tried to delete the same cache node, the "ignore long locked
inactive cache entry" alert appeared in logs. Additionally,
ngx_http_file_cache_forced_expire() might be also called by worker
processes, with similar results.
Fix is to ignore cache nodes being deleted, similarly to how it is
done in ngx_http_file_cache_expire() since 3755:76e3a93821b1. This
was somehow missed in 7002:ab199f0eb8e8, when ignoring long locked
cache entries was introduced in ngx_http_file_cache_forced_expire().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 01 Feb 2022 16:29:28 +0300 |
parents | 1bde031b59ff |
children | d26db4f82d7d |
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:
416
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:
416
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:
416
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:
416
diff
changeset
|
6 |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
87
5f6d848dcbef
nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
74
diff
changeset
|
9 #include <ngx_core.h> |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
10 #include <ngx_http.h> |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
11 |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
13 static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r); |
681 | 14 static ngx_int_t ngx_http_static_init(ngx_conf_t *cf); |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
15 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
16 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6853
diff
changeset
|
17 static ngx_http_module_t ngx_http_static_module_ctx = { |
509 | 18 NULL, /* preconfiguration */ |
681 | 19 ngx_http_static_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
20 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
21 NULL, /* create main configuration */ |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
22 NULL, /* init main configuration */ |
577 | 23 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
24 NULL, /* create server configuration */ |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
25 NULL, /* merge server configuration */ |
577 | 26 |
1454 | 27 NULL, /* create location configuration */ |
28 NULL /* merge location configuration */ | |
577 | 29 }; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
30 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
31 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
32 ngx_module_t ngx_http_static_module = { |
509 | 33 NGX_MODULE_V1, |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
34 &ngx_http_static_module_ctx, /* module context */ |
1454 | 35 NULL, /* module directives */ |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
36 NGX_HTTP_MODULE, /* module type */ |
541 | 37 NULL, /* init master */ |
681 | 38 NULL, /* init module */ |
541 | 39 NULL, /* init process */ |
40 NULL, /* init thread */ | |
41 NULL, /* exit thread */ | |
42 NULL, /* exit process */ | |
43 NULL, /* exit master */ | |
44 NGX_MODULE_V1_PADDING | |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
45 }; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
46 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
47 |
509 | 48 static ngx_int_t |
49 ngx_http_static_handler(ngx_http_request_t *r) | |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
50 { |
557 | 51 u_char *last, *location; |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
52 size_t root, len; |
8469
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
53 uintptr_t escape; |
1454 | 54 ngx_str_t path; |
557 | 55 ngx_int_t rc; |
56 ngx_uint_t level; | |
57 ngx_log_t *log; | |
58 ngx_buf_t *b; | |
59 ngx_chain_t out; | |
1454 | 60 ngx_open_file_info_t of; |
557 | 61 ngx_http_core_loc_conf_t *clcf; |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
62 |
2182
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
63 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) { |
639 | 64 return NGX_HTTP_NOT_ALLOWED; |
65 } | |
66 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
67 if (r->uri.data[r->uri.len - 1] == '/') { |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
68 return NGX_DECLINED; |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
69 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
70 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
71 log = r->connection->log; |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
72 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
73 /* |
557 | 74 * ngx_http_map_uri_to_path() allocates memory for terminating '\0' |
75 * so we do not need to reserve memory for '/' for possible redirect | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
76 */ |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
77 |
773 | 78 last = ngx_http_map_uri_to_path(r, &path, &root, 0); |
557 | 79 if (last == NULL) { |
80 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
400
69e851f83522
nginx-0.0.8-2004-07-26-20:21:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
81 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
82 |
1454 | 83 path.len = last - path.data; |
84 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
85 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, |
557 | 86 "http filename: \"%s\"", path.data); |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
87 |
1454 | 88 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
563 | 89 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
90 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); |
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
91 |
3178 | 92 of.read_ahead = clcf->read_ahead; |
2129 | 93 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1696
diff
changeset
|
94 of.valid = clcf->open_file_cache_valid; |
1772 | 95 of.min_uses = clcf->open_file_cache_min_uses; |
1454 | 96 of.errors = clcf->open_file_cache_errors; |
1457 | 97 of.events = clcf->open_file_cache_events; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
98 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
99 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
100 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
101 } |
1454 | 102 |
1799 | 103 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
104 != NGX_OK) | |
105 { | |
1454 | 106 switch (of.err) { |
107 | |
108 case 0: | |
109 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
110 |
1454 | 111 case NGX_ENOENT: |
112 case NGX_ENOTDIR: | |
113 case NGX_ENAMETOOLONG: | |
114 | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
115 level = NGX_LOG_ERR; |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
116 rc = NGX_HTTP_NOT_FOUND; |
1454 | 117 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
118 |
1454 | 119 case NGX_EACCES: |
4478
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
120 #if (NGX_HAVE_OPENAT) |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
121 case NGX_EMLINK: |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
122 case NGX_ELOOP: |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
123 #endif |
1454 | 124 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
125 level = NGX_LOG_ERR; |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
126 rc = NGX_HTTP_FORBIDDEN; |
1454 | 127 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
128 |
1454 | 129 default: |
130 | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
131 level = NGX_LOG_CRIT; |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
132 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
1454 | 133 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
134 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
135 |
527 | 136 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) { |
1454 | 137 ngx_log_error(level, log, of.err, |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
138 "%s \"%s\" failed", of.failed, path.data); |
527 | 139 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
140 |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
141 return rc; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
142 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
143 |
2444
aee735f41627
set r->root_tested for non-error_page response only
Igor Sysoev <igor@sysoev.ru>
parents:
2403
diff
changeset
|
144 r->root_tested = !r->error_page; |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2068
diff
changeset
|
145 |
1696 | 146 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd); |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
147 |
1454 | 148 if (of.is_dir) { |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
149 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
150 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir"); |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
151 |
4206
1a94a56a4e5d
Clear old Location header (if any) while adding a new one.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3527
diff
changeset
|
152 ngx_http_clear_location(r); |
1a94a56a4e5d
Clear old Location header (if any) while adding a new one.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3527
diff
changeset
|
153 |
6853
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6306
diff
changeset
|
154 r->headers_out.location = ngx_list_push(&r->headers_out.headers); |
416
b9bd635011de
nginx-0.0.10-2004-09-06-22:45:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
155 if (r->headers_out.location == NULL) { |
165
894a01c6aea3
nginx-0.0.1-2003-10-29-20:39:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
156 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
894a01c6aea3
nginx-0.0.1-2003-10-29-20:39:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
157 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
158 |
8469
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
159 escape = 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
160 NGX_ESCAPE_URI); |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
161 |
8469
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
162 if (!clcf->alias && r->args.len == 0 && escape == 0) { |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
163 len = r->uri.len + 1; |
7602
b399246ea45d
Saved some memory allocations.
Ruslan Ermilov <ru@nginx.com>
parents:
6986
diff
changeset
|
164 location = path.data + root; |
557 | 165 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
166 *last = '/'; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
167 |
557 | 168 } else { |
8469
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
169 len = r->uri.len + escape + 1; |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
170 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
171 if (r->args.len) { |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
172 len += r->args.len + 1; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
173 } |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
174 |
2049 | 175 location = ngx_pnalloc(r->pool, len); |
557 | 176 if (location == NULL) { |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6973
diff
changeset
|
177 ngx_http_clear_location(r); |
557 | 178 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
179 } | |
180 | |
8469
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
181 if (escape) { |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
182 last = (u_char *) ngx_escape_uri(location, r->uri.data, |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
183 r->uri.len, NGX_ESCAPE_URI); |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
184 |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
185 } else { |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
186 last = ngx_copy(location, r->uri.data, r->uri.len); |
1bde031b59ff
Location header escaping in redirects (ticket #882).
Ruslan Ermilov <ru@nginx.com>
parents:
7602
diff
changeset
|
187 } |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
188 |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
189 *last = '/'; |
557 | 190 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
191 if (r->args.len) { |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
192 *++last = '?'; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
193 ngx_memcpy(++last, r->args.data, r->args.len); |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
194 } |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
195 } |
557 | 196 |
6853
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6306
diff
changeset
|
197 r->headers_out.location->hash = 1; |
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6306
diff
changeset
|
198 ngx_str_set(&r->headers_out.location->key, "Location"); |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
199 r->headers_out.location->value.len = len; |
557 | 200 r->headers_out.location->value.data = location; |
287
35a6a9df2d25
nginx-0.0.2-2004-03-12-19:57:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
201 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
202 return NGX_HTTP_MOVED_PERMANENTLY; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
203 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
204 |
461 | 205 #if !(NGX_WIN32) /* the not regular files are probably Unix specific */ |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
206 |
1454 | 207 if (!of.is_file) { |
3498
9f20a6e758c3
do not log misleading errno in "not a regular file" error
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
208 ngx_log_error(NGX_LOG_CRIT, log, 0, |
557 | 209 "\"%s\" is not a regular file", path.data); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
210 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
211 return NGX_HTTP_NOT_FOUND; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
212 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
213 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
214 #endif |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
215 |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
4748
diff
changeset
|
216 if (r->method == NGX_HTTP_POST) { |
2182
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
217 return NGX_HTTP_NOT_ALLOWED; |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
218 } |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
219 |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
220 rc = ngx_http_discard_request_body(r); |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
221 |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
222 if (rc != NGX_OK) { |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
223 return rc; |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
224 } |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
225 |
509 | 226 log->action = "sending response to client"; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
227 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
228 r->headers_out.status = NGX_HTTP_OK; |
1454 | 229 r->headers_out.content_length_n = of.size; |
230 r->headers_out.last_modified_time = of.mtime; | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
231 |
4748
192f54280a7a
Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4494
diff
changeset
|
232 if (ngx_http_set_etag(r) != NGX_OK) { |
192f54280a7a
Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4494
diff
changeset
|
233 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
192f54280a7a
Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4494
diff
changeset
|
234 } |
192f54280a7a
Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4494
diff
changeset
|
235 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
236 if (ngx_http_set_content_type(r) != NGX_OK) { |
200
abeaebe0a33c
nginx-0.0.1-2003-11-28-20:41:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
199
diff
changeset
|
237 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
abeaebe0a33c
nginx-0.0.1-2003-11-28-20:41:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
199
diff
changeset
|
238 } |
abeaebe0a33c
nginx-0.0.1-2003-11-28-20:41:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
199
diff
changeset
|
239 |
2403
5e5caa72f61e
fix zero length static response, the bug was introduced in r2378
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
240 if (r != r->main && of.size == 0) { |
583 | 241 return ngx_http_send_header(r); |
242 } | |
243 | |
587 | 244 r->allow_ranges = 1; |
245 | |
577 | 246 /* we need to allocate all before the header would be sent */ |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 |
6973
99934aade555
Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6922
diff
changeset
|
248 b = ngx_calloc_buf(r->pool); |
577 | 249 if (b == NULL) { |
250 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
251 } | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
252 |
577 | 253 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); |
254 if (b->file == NULL) { | |
255 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
256 } | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
400
diff
changeset
|
257 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
258 rc = ngx_http_send_header(r); |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
259 |
585 | 260 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { |
143
5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
142
diff
changeset
|
261 return rc; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
262 } |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
263 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
334
diff
changeset
|
264 b->file_pos = 0; |
1454 | 265 b->file_last = of.size; |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 |
577 | 267 b->in_file = b->file_last ? 1: 0; |
597 | 268 b->last_buf = (r == r->main) ? 1: 0; |
577 | 269 b->last_in_chain = 1; |
270 | |
1696 | 271 b->file->fd = of.fd; |
557 | 272 b->file->name = path; |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
334
diff
changeset
|
273 b->file->log = log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2182
diff
changeset
|
274 b->file->directio = of.is_directio; |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
334
diff
changeset
|
275 |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
334
diff
changeset
|
276 out.buf = b; |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
277 out.next = NULL; |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
278 |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
279 return ngx_http_output_filter(r, &out); |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
280 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
281 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
282 |
509 | 283 static ngx_int_t |
681 | 284 ngx_http_static_init(ngx_conf_t *cf) |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
285 { |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
286 ngx_http_handler_pt *h; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
287 ngx_http_core_main_conf_t *cmcf; |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
288 |
681 | 289 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
577 | 290 |
501 | 291 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
292 if (h == NULL) { |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
293 return NGX_ERROR; |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
294 } |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
295 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
296 *h = ngx_http_static_handler; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
297 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
298 return NGX_OK; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
299 } |