Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_static_module.c @ 2235:03180d4e5af2
ngx_http_random_index_module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 05 Sep 2008 15:45:55 +0000 |
parents | 8564129d49b6 |
children | 87b8c44906b5 |
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 |
489 | 69 /* TODO: Win32 */ |
70 if (r->zero_in_uri) { | |
71 return NGX_DECLINED; | |
72 } | |
73 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
74 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
|
75 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
76 /* |
557 | 77 * ngx_http_map_uri_to_path() allocates memory for terminating '\0' |
78 * 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
|
79 */ |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
80 |
773 | 81 last = ngx_http_map_uri_to_path(r, &path, &root, 0); |
557 | 82 if (last == NULL) { |
83 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
|
84 } |
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 path.len = last - path.data; |
87 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
88 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, |
557 | 89 "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
|
90 |
1454 | 91 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
563 | 92 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
93 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
|
94 |
2129 | 95 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1696
diff
changeset
|
96 of.valid = clcf->open_file_cache_valid; |
1772 | 97 of.min_uses = clcf->open_file_cache_min_uses; |
1454 | 98 of.errors = clcf->open_file_cache_errors; |
1457 | 99 of.events = clcf->open_file_cache_events; |
1454 | 100 |
1799 | 101 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
102 != NGX_OK) | |
103 { | |
1454 | 104 switch (of.err) { |
105 | |
106 case 0: | |
107 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
|
108 |
1454 | 109 case NGX_ENOENT: |
110 case NGX_ENOTDIR: | |
111 case NGX_ENAMETOOLONG: | |
112 | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
113 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
|
114 rc = NGX_HTTP_NOT_FOUND; |
1454 | 115 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
116 |
1454 | 117 case NGX_EACCES: |
118 | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
119 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
|
120 rc = NGX_HTTP_FORBIDDEN; |
1454 | 121 break; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
122 |
1454 | 123 default: |
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_CRIT; |
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_INTERNAL_SERVER_ERROR; |
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 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
129 |
527 | 130 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) { |
1454 | 131 ngx_log_error(level, log, of.err, |
557 | 132 ngx_open_file_n " \"%s\" failed", path.data); |
527 | 133 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
134 |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
135 return rc; |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
136 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
137 |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2068
diff
changeset
|
138 r->root_tested = 1; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2068
diff
changeset
|
139 |
1696 | 140 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
|
141 |
1454 | 142 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
|
143 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
144 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
|
145 |
509 | 146 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
|
147 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
|
148 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
|
149 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
150 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
151 len = r->uri.len + 1; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
152 |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
153 if (!clcf->alias && clcf->root_lengths == NULL && r->args.len == 0) { |
557 | 154 location = path.data + clcf->root.len; |
155 | |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
156 *last = '/'; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
157 |
557 | 158 } else { |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
159 if (r->args.len) { |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
160 len += r->args.len + 1; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
161 } |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
162 |
2049 | 163 location = ngx_pnalloc(r->pool, len); |
557 | 164 if (location == NULL) { |
165 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
166 } | |
167 | |
573 | 168 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
|
169 |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
170 *last = '/'; |
557 | 171 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
172 if (r->args.len) { |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
173 *++last = '?'; |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
174 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
|
175 } |
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
176 } |
557 | 177 |
509 | 178 /* |
179 * we do not need to set the r->headers_out.location->hash and | |
180 * r->headers_out.location->key fields | |
181 */ | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
182 |
2038
93a0d80fdce6
add args in redirect to a directory
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
183 r->headers_out.location->value.len = len; |
557 | 184 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
|
185 |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
186 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
|
187 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
188 |
461 | 189 #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
|
190 |
1454 | 191 if (!of.is_file) { |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
192 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
557 | 193 "\"%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
|
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 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
|
196 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
197 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
198 #endif |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
199 |
2182
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
200 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
|
201 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
|
202 } |
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 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
|
205 |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
206 if (rc != NGX_OK) { |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
207 return rc; |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
208 } |
23309bcd9937
allow file existence test for POST requests in static module
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
209 |
509 | 210 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
|
211 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
212 r->headers_out.status = NGX_HTTP_OK; |
1454 | 213 r->headers_out.content_length_n = of.size; |
214 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
|
215 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
216 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
|
217 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
|
218 } |
abeaebe0a33c
nginx-0.0.1-2003-11-28-20:41:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
199
diff
changeset
|
219 |
1454 | 220 if (r != r->main && of.size == 0) { |
583 | 221 return ngx_http_send_header(r); |
222 } | |
223 | |
587 | 224 r->allow_ranges = 1; |
225 | |
577 | 226 /* 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
|
227 |
577 | 228 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); |
229 if (b == NULL) { | |
230 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
231 } | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
232 |
577 | 233 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); |
234 if (b->file == NULL) { | |
235 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
236 } | |
403
ea3113b181d1
nginx-0.0.9-2004-07-28-23:21:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
400
diff
changeset
|
237 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
238 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
|
239 |
585 | 240 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
|
241 return rc; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
242 } |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
243 |
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
|
244 b->file_pos = 0; |
1454 | 245 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
|
246 |
577 | 247 b->in_file = b->file_last ? 1: 0; |
597 | 248 b->last_buf = (r == r->main) ? 1: 0; |
577 | 249 b->last_in_chain = 1; |
250 | |
1696 | 251 b->file->fd = of.fd; |
557 | 252 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
|
253 b->file->log = log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2182
diff
changeset
|
254 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
|
255 |
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
|
256 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
|
257 out.next = NULL; |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
258 |
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
259 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
|
260 } |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
261 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
262 |
509 | 263 static ngx_int_t |
681 | 264 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
|
265 { |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
266 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
|
267 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
|
268 |
681 | 269 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
577 | 270 |
501 | 271 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
|
272 if (h == NULL) { |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
273 return NGX_ERROR; |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
274 } |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
275 |
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
276 *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
|
277 |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
278 return NGX_OK; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
279 } |