Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_static_module.c @ 4247:b79dbadb3d5e stable-1.0
Merging r4147, r4148, r4149, r4150, r4207:
Fixes of combination of error_page and return directives:
*) Fix for incorrect 201 replies from dav module.
Replies with 201 code contain body, and we should clearly indicate it's
empty if it's empty. Before 0.8.32 chunked was explicitly disabled for
201 replies and as a result empty body was indicated by connection close
(not perfect, but worked). Since 0.8.32 chunked is enabled, and this
causes incorrect responses from dav module when HTTP/1.1 is used: with
"Transfer-Encoding: chunked" but no chunks at all.
Fix is to actually return empty body in special response handler instead
of abusing r->header_only flag.
See here for initial report:
http://mailman.nginx.org/pipermail/nginx-ru/2010-October/037535.html
*) Fix for double content when return is used in error_page handler.
Test case:
location / {
error_page 405 /nope;
return 405;
}
location /nope {
return 200;
}
This is expected to return 405 with empty body, but in 0.8.42+ will return
builtin 405 error page as well (though not counted in Content-Length, thus
breaking protocol).
Fix is to use status provided by rewrite script execution in case
it's less than NGX_HTTP_BAD_REQUEST even if r->error_status set. This
check is in line with one in ngx_http_script_return_code().
Note that this patch also changes behaviour for "return 302 ..." and
"rewrite ... redirect" used as error handler. E.g.
location / {
error_page 405 /redirect;
return 405;
}
location /redirect {
rewrite ^ http://example.com/;
}
will actually return redirect to "http://example.com/" instead of builtin
405 error page with meaningless Location header. This looks like correct
change and it's in line with what happens on e.g. directory redirects
in error handlers.
*) Fix for "return 202" not discarding body.
Big POST (not fully preread) to a
location / {
return 202;
}
resulted in incorrect behaviour due to "return" code path not calling
ngx_http_discard_request_body(). The same applies to all "return" used
with 2xx/3xx codes except 201 and 204, and to all "return ... text" uses.
Fix is to add ngx_http_discard_request_body() call to
ngx_http_send_response() function where it looks appropriate.
Discard body call from emtpy gif module removed as it's now redundant.
Reported by Pyry Hakulinen, see
http://mailman.nginx.org/pipermail/nginx/2011-August/028503.html
*) Incorrect special case for "return 204" removed.
The special case in question leads to replies without body in
configuration like
location / { error_page 404 /zero; return 404; }
location /zero { return 204; }
while replies with empty body are expected per protocol specs.
Correct one will look like
if (status == NGX_HTTP_NO_CONTENT) {
rc = ngx_http_send_header(r);
if (rc == NGX_ERROR || r->header_only) {
return rc;
}
return ngx_http_send_special(r, NGX_HTTP_LAST);
}
though it looks like it's better to drop this special case at all.
*) Clear old Location header (if any) while adding a new one.
This prevents incorrect behaviour when another redirect is issued within
error_page 302 handler.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 01 Nov 2011 13:45:33 +0000 |
parents | 84905c7b2aa7 |
children | d620f497c50f |
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 |
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
|
4 */ |
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 |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #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
|
8 #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
|
9 #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
|
10 |
1
d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
12 static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r); |
681 | 13 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
|
14 |
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 ngx_http_module_t ngx_http_static_module_ctx = { |
509 | 17 NULL, /* preconfiguration */ |
681 | 18 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
|
19 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
20 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
|
21 NULL, /* init main configuration */ |
577 | 22 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
23 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
|
24 NULL, /* merge server configuration */ |
577 | 25 |
1454 | 26 NULL, /* create location configuration */ |
27 NULL /* merge location configuration */ | |
577 | 28 }; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
29 |
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 ngx_module_t ngx_http_static_module = { |
509 | 32 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
|
33 &ngx_http_static_module_ctx, /* module context */ |
1454 | 34 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
|
35 NGX_HTTP_MODULE, /* module type */ |
541 | 36 NULL, /* init master */ |
681 | 37 NULL, /* init module */ |
541 | 38 NULL, /* init process */ |
39 NULL, /* init thread */ | |
40 NULL, /* exit thread */ | |
41 NULL, /* exit process */ | |
42 NULL, /* exit master */ | |
43 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
|
44 }; |
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 |
509 | 47 static ngx_int_t |
48 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
|
49 { |
557 | 50 u_char *last, *location; |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
51 size_t root, len; |
1454 | 52 ngx_str_t path; |
557 | 53 ngx_int_t rc; |
54 ngx_uint_t level; | |
55 ngx_log_t *log; | |
56 ngx_buf_t *b; | |
57 ngx_chain_t out; | |
1454 | 58 ngx_open_file_info_t of; |
557 | 59 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
|
60 |
2182
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
61 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) { |
639 | 62 return NGX_HTTP_NOT_ALLOWED; |
63 } | |
64 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
65 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
|
66 return NGX_DECLINED; |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
67 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
68 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
69 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
|
70 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
71 /* |
557 | 72 * ngx_http_map_uri_to_path() allocates memory for terminating '\0' |
73 * 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
|
74 */ |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
75 |
773 | 76 last = ngx_http_map_uri_to_path(r, &path, &root, 0); |
557 | 77 if (last == NULL) { |
78 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
|
79 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
80 |
1454 | 81 path.len = last - path.data; |
82 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
83 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, |
557 | 84 "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
|
85 |
1454 | 86 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
563 | 87 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
88 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
|
89 |
3178 | 90 of.read_ahead = clcf->read_ahead; |
2129 | 91 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1696
diff
changeset
|
92 of.valid = clcf->open_file_cache_valid; |
1772 | 93 of.min_uses = clcf->open_file_cache_min_uses; |
1454 | 94 of.errors = clcf->open_file_cache_errors; |
1457 | 95 of.events = clcf->open_file_cache_events; |
1454 | 96 |
1799 | 97 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
98 != NGX_OK) | |
99 { | |
1454 | 100 switch (of.err) { |
101 | |
102 case 0: | |
103 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
|
104 |
1454 | 105 case NGX_ENOENT: |
106 case NGX_ENOTDIR: | |
107 case NGX_ENAMETOOLONG: | |
108 | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
109 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
|
110 rc = NGX_HTTP_NOT_FOUND; |
1454 | 111 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
112 |
1454 | 113 case NGX_EACCES: |
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_FORBIDDEN; |
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 default: |
120 | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
121 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
|
122 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
1454 | 123 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
124 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
125 |
527 | 126 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) { |
1454 | 127 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
|
128 "%s \"%s\" failed", of.failed, path.data); |
527 | 129 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
130 |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
131 return rc; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
132 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
133 |
2444
aee735f41627
set r->root_tested for non-error_page response only
Igor Sysoev <igor@sysoev.ru>
parents:
2403
diff
changeset
|
134 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
|
135 |
1696 | 136 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
|
137 |
1454 | 138 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
|
139 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
140 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
|
141 |
4247
b79dbadb3d5e
Merging r4147, r4148, r4149, r4150, r4207:
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
142 ngx_http_clear_location(r); |
b79dbadb3d5e
Merging r4147, r4148, r4149, r4150, r4207:
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
143 |
509 | 144 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t)); |
416
b9bd635011de
nginx-0.0.10-2004-09-06-22:45:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
145 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
|
146 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
|
147 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
148 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
149 len = r->uri.len + 1; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
150 |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
151 if (!clcf->alias && clcf->root_lengths == NULL && r->args.len == 0) { |
557 | 152 location = path.data + clcf->root.len; |
153 | |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
154 *last = '/'; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
155 |
557 | 156 } else { |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
157 if (r->args.len) { |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
158 len += r->args.len + 1; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
159 } |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
160 |
2049 | 161 location = ngx_pnalloc(r->pool, len); |
557 | 162 if (location == NULL) { |
163 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
164 } | |
165 | |
573 | 166 last = ngx_copy(location, r->uri.data, r->uri.len); |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
167 |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
168 *last = '/'; |
557 | 169 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
170 if (r->args.len) { |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
171 *++last = '?'; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
172 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
|
173 } |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
174 } |
557 | 175 |
509 | 176 /* |
177 * we do not need to set the r->headers_out.location->hash and | |
178 * r->headers_out.location->key fields | |
179 */ | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
180 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
181 r->headers_out.location->value.len = len; |
557 | 182 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
|
183 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
184 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
|
185 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
186 |
461 | 187 #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
|
188 |
1454 | 189 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
|
190 ngx_log_error(NGX_LOG_CRIT, log, 0, |
557 | 191 "\"%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
|
192 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
193 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
|
194 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
195 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
196 #endif |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
197 |
2182
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
198 if (r->method & NGX_HTTP_POST) { |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
199 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
|
200 } |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
201 |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
202 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
|
203 |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
204 if (rc != NGX_OK) { |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
205 return rc; |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
206 } |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
207 |
509 | 208 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
|
209 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
210 r->headers_out.status = NGX_HTTP_OK; |
1454 | 211 r->headers_out.content_length_n = of.size; |
212 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
|
213 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
214 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
|
215 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
|
216 } |
abeaebe0a33c
nginx-0.0.1-2003-11-28-20:41:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
199
diff
changeset
|
217 |
2403
5e5caa72f61e
fix zero length static response, the bug was introduced in r2378
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
218 if (r != r->main && of.size == 0) { |
583 | 219 return ngx_http_send_header(r); |
220 } | |
221 | |
587 | 222 r->allow_ranges = 1; |
223 | |
577 | 224 /* 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
|
225 |
577 | 226 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); |
227 if (b == NULL) { | |
228 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
229 } | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
230 |
577 | 231 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); |
232 if (b->file == NULL) { | |
233 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
234 } | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
400
diff
changeset
|
235 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
236 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
|
237 |
585 | 238 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
|
239 return rc; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
240 } |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
241 |
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
|
242 b->file_pos = 0; |
1454 | 243 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
|
244 |
577 | 245 b->in_file = b->file_last ? 1: 0; |
597 | 246 b->last_buf = (r == r->main) ? 1: 0; |
577 | 247 b->last_in_chain = 1; |
248 | |
1696 | 249 b->file->fd = of.fd; |
557 | 250 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
|
251 b->file->log = log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2182
diff
changeset
|
252 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
|
253 |
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
|
254 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
|
255 out.next = NULL; |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
256 |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
257 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
|
258 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
259 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
260 |
509 | 261 static ngx_int_t |
681 | 262 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
|
263 { |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
264 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
|
265 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
|
266 |
681 | 267 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
577 | 268 |
501 | 269 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
|
270 if (h == NULL) { |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
271 return NGX_ERROR; |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
272 } |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
273 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
274 *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
|
275 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
276 return NGX_OK; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
277 } |