annotate src/http/modules/ngx_http_static_module.c @ 508:68c0ae0a4959 NGINX_0_7_66

nginx 0.7.66 *) Security: now nginx/Windows ignores default file stream name. Thanks to Jose Antonio Vazquez Gonzalez. *) Change: now the charset filter runs before the SSI filter. *) Change: now no message is written in an error log if a variable is not found by $r->variable() method. *) Change: now keepalive connections after POST requests are not disabled for MSIE 7.0+. Thanks to Adam Lounds. *) Feature: the "proxy_no_cache" and "fastcgi_no_cache" directives. *) Feature: now the "rewrite" directive does a redirect automatically if the $scheme variable is used. Thanks to Piotr Sikora. *) Feature: the "chunked_transfer_encoding" directive. *) Feature: the $geoip_city_continent_code, $geoip_latitude, and $geoip_longitude variables. Thanks to Arvind Sundararajan. *) Feature: now the ngx_http_image_filter_module deletes always EXIF and other application specific data if the data consume more than 5% of a JPEG file. *) Feature: now the "msie_padding" directive works for Chrome too. *) Workaround: now keepalive connections are disabled for Safari. Thanks to Joshua Sierles. *) Bugfix: nginx ignored the "private" and "no-store" values in the "Cache-Control" backend response header line. *) Bugfix: an "&" character was not escaped when it was copied in arguments part in a rewrite rule. *) Bugfix: nginx might be terminated abnormally while a signal processing or if the directive "timer_resolution" was used on platforms which do not support kqueue or eventport notification methods. Thanks to George Xie and Maxim Dounin. *) Bugfix: if temporary files and permanent storage area resided at different file systems, then permanent file modification times were incorrect. Thanks to Maxim Dounin. *) Bugfix: ngx_http_memcached_module might issue the error message "memcached sent invalid trailer". Thanks to Maxim Dounin. *) Bugfix: nginx could not built zlib-1.2.4 library using the library sources. Thanks to Maxim Dounin. *) Bugfix: values of the $query_string, $arg_..., etc. variables cached in main request were used by the SSI module in subrequests. *) Bugfix: nginx did not support HTTPS referrers. *) Bugfix: nginx/Windows might not find file if path in configuration was given in other character case; the bug had appeared in 0.7.65. *) Bugfix: the $date_local variable has an incorrect value, if the "%s" format was used. Thanks to Maxim Dounin. *) Bugfix: nginx did not support all ciphers and digests used in client certificates. Thanks to Innocenty Enikeew. *) Bugfix: if ssl_session_cache was not set or was set to "none", then during client certificate verify the error "session id context uninitialized" might occur; the bug had appeared in 0.7.1. *) Bugfix: OpenSSL-1.0.0 compatibility on 64-bit Linux. Thanks to Maxim Dounin. *) Bugfix: a geo range returned default value if the range included two or more /16 networks and did not begin at /16 network boundary. *) Bugfix: the $uid_got variable might not be used in the SSI and perl modules. *) Bugfix: a worker process hung if a FIFO file was requested. Thanks to Vicente Aguilar and Maxim Dounin. *) Bugfix: a variable value was repeatedly encoded after each an "echo" SSI-command output; the bug had appeared in 0.6.14. *) Bugfix: a "stub" parameter of an "include" SSI directive was not used, if empty response has 200 status code. *) Bugfix: a block used in a "stub" parameter of an "include" SSI directive was output with "text/plain" MIME type. *) Bugfix: if a proxied or FastCGI request was internally redirected to another proxied or FastCGI location, then a segmentation fault might occur in a worker process; the bug had appeared in 0.7.65. Thanks to Yichun Zhang. *) Bugfix: IMAP connections may hang until they timed out while talking to Zimbra server. Thanks to Alan Batie. *) Bugfix: nginx did not support chunked transfer encoding for 201 responses. Thanks to Julian Reich.
author Igor Sysoev <http://sysoev.ru>
date Mon, 07 Jun 2010 00:00:00 +0400
parents 392c16f2d858
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r);
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 194
diff changeset
13 static ngx_int_t ngx_http_static_init(ngx_conf_t *cf);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 ngx_http_module_t ngx_http_static_module_ctx = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
17 NULL, /* preconfiguration */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 194
diff changeset
18 ngx_http_static_init, /* postconfiguration */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 NULL, /* create main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 NULL, /* init main configuration */
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
22
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23 NULL, /* create server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 NULL, /* merge server configuration */
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
25
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
26 NULL, /* create location configuration */
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
27 NULL /* merge location configuration */
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
28 };
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 ngx_module_t ngx_http_static_module = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
32 NGX_MODULE_V1,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 &ngx_http_static_module_ctx, /* module context */
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
34 NULL, /* module directives */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 NGX_HTTP_MODULE, /* module type */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
36 NULL, /* init master */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 194
diff changeset
37 NULL, /* init module */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
38 NULL, /* init process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
39 NULL, /* init thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
40 NULL, /* exit thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
41 NULL, /* exit process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
42 NULL, /* exit master */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
43 NGX_MODULE_V1_PADDING
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
47 static ngx_int_t
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
48 ngx_http_static_handler(ngx_http_request_t *r)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 {
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
50 u_char *last, *location;
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
51 size_t root, len;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
52 ngx_str_t path;
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
53 ngx_int_t rc;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
54 ngx_uint_t level;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
55 ngx_log_t *log;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
56 ngx_buf_t *b;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
57 ngx_chain_t out;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
58 ngx_open_file_info_t of;
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
59 ngx_http_core_loc_conf_t *clcf;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60
398
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
61 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) {
188
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 152
diff changeset
62 return NGX_HTTP_NOT_ALLOWED;
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 152
diff changeset
63 }
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 152
diff changeset
64
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 if (r->uri.data[r->uri.len - 1] == '/') {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 return NGX_DECLINED;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 log = r->connection->log;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 /*
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
72 * ngx_http_map_uri_to_path() allocates memory for terminating '\0'
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
73 * so we do not need to reserve memory for '/' for possible redirect
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75
248
acd2ec3541cb nginx 0.4.9
Igor Sysoev <http://sysoev.ru>
parents: 234
diff changeset
76 last = ngx_http_map_uri_to_path(r, &path, &root, 0);
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
77 if (last == NULL) {
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
78 return NGX_HTTP_INTERNAL_SERVER_ERROR;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
81 path.len = last - path.data;
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
82
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
84 "http filename: \"%s\"", path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
86 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
87
384
12defd37f578 nginx 0.7.4
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
88 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
12defd37f578 nginx 0.7.4
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
89
390
0b6053502c55 nginx 0.7.7
Igor Sysoev <http://sysoev.ru>
parents: 388
diff changeset
90 of.directio = clcf->directio;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
91 of.valid = clcf->open_file_cache_valid;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 356
diff changeset
92 of.min_uses = clcf->open_file_cache_min_uses;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
93 of.errors = clcf->open_file_cache_errors;
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
94 of.events = clcf->open_file_cache_events;
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
95
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
96 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
97 != NGX_OK)
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
98 {
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
99 switch (of.err) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
101 case 0:
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
102 return NGX_HTTP_INTERNAL_SERVER_ERROR;
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
103
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
104 case NGX_ENOENT:
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
105 case NGX_ENOTDIR:
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
106 case NGX_ENAMETOOLONG:
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
107
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 level = NGX_LOG_ERR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 rc = NGX_HTTP_NOT_FOUND;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
110 break;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
112 case NGX_EACCES:
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
113
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 level = NGX_LOG_ERR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 rc = NGX_HTTP_FORBIDDEN;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
116 break;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
118 default:
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
119
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 level = NGX_LOG_CRIT;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
122 break;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
125 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
126 ngx_log_error(level, log, of.err,
482
392c16f2d858 nginx 0.7.53
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
127 "%s \"%s\" failed", of.failed, path.data);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
128 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 return rc;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132
438
ce4f9ff90bfa nginx 0.7.31
Igor Sysoev <http://sysoev.ru>
parents: 430
diff changeset
133 r->root_tested = !r->error_page;
388
6de24473fa70 nginx 0.7.6
Igor Sysoev <http://sysoev.ru>
parents: 384
diff changeset
134
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 332
diff changeset
135 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
137 if (of.is_dir) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir");
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
141 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142 if (r->headers_out.location == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 return NGX_HTTP_INTERNAL_SERVER_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
146 len = r->uri.len + 1;
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
147
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
148 if (!clcf->alias && clcf->root_lengths == NULL && r->args.len == 0) {
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
149 location = path.data + clcf->root.len;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
150
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
151 *last = '/';
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
152
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
153 } else {
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
154 if (r->args.len) {
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
155 len += r->args.len + 1;
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
156 }
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
157
382
984bb0b1399b nginx 0.7.3
Igor Sysoev <http://sysoev.ru>
parents: 380
diff changeset
158 location = ngx_pnalloc(r->pool, len);
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
159 if (location == NULL) {
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
160 return NGX_HTTP_INTERNAL_SERVER_ERROR;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
161 }
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
162
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 112
diff changeset
163 last = ngx_copy(location, r->uri.data, r->uri.len);
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
164
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
165 *last = '/';
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
166
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
167 if (r->args.len) {
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
168 *++last = '?';
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
169 ngx_memcpy(++last, r->args.data, r->args.len);
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
170 }
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
171 }
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
172
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
173 /*
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
174 * we do not need to set the r->headers_out.location->hash and
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
175 * r->headers_out.location->key fields
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
176 */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
380
bc21d9cd9c54 nginx 0.7.2
Igor Sysoev <http://sysoev.ru>
parents: 362
diff changeset
178 r->headers_out.location->value.len = len;
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
179 r->headers_out.location->value.data = location;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 return NGX_HTTP_MOVED_PERMANENTLY;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 #if !(NGX_WIN32) /* the not regular files are probably Unix specific */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
186 if (!of.is_file) {
508
68c0ae0a4959 nginx 0.7.66
Igor Sysoev <http://sysoev.ru>
parents: 482
diff changeset
187 ngx_log_error(NGX_LOG_CRIT, log, 0,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
188 "\"%s\" is not a regular file", path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190 return NGX_HTTP_NOT_FOUND;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 #endif
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194
398
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
195 if (r->method & NGX_HTTP_POST) {
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
196 return NGX_HTTP_NOT_ALLOWED;
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
197 }
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
198
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
199 rc = ngx_http_discard_request_body(r);
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
200
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
201 if (rc != NGX_OK) {
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
202 return rc;
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
203 }
9d81578d04bb nginx 0.7.11
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
204
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
205 log->action = "sending response to client";
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 r->headers_out.status = NGX_HTTP_OK;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
208 r->headers_out.content_length_n = of.size;
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
209 r->headers_out.last_modified_time = of.mtime;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 if (ngx_http_set_content_type(r) != NGX_OK) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 return NGX_HTTP_INTERNAL_SERVER_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214
430
dac47e9ef0d5 nginx 0.7.27
Igor Sysoev <http://sysoev.ru>
parents: 426
diff changeset
215 if (r != r->main && of.size == 0) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
216 return ngx_http_send_header(r);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
217 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
218
136
3656228c0b56 nginx 0.3.15
Igor Sysoev <http://sysoev.ru>
parents: 134
diff changeset
219 r->allow_ranges = 1;
3656228c0b56 nginx 0.3.15
Igor Sysoev <http://sysoev.ru>
parents: 134
diff changeset
220
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
221 /* we need to allocate all before the header would be sent */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
223 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
224 if (b == NULL) {
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
225 return NGX_HTTP_INTERNAL_SERVER_ERROR;
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
226 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
228 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
229 if (b->file == NULL) {
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
230 return NGX_HTTP_INTERNAL_SERVER_ERROR;
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
231 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 rc = ngx_http_send_header(r);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234
134
1898c6d03d90 nginx 0.3.14
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
235 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 return rc;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 b->file_pos = 0;
332
3a91bfeffaba nginx 0.6.10
Igor Sysoev <http://sysoev.ru>
parents: 326
diff changeset
240 b->file_last = of.size;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
242 b->in_file = b->file_last ? 1: 0;
146
36af50a5582d nginx 0.3.20
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
243 b->last_buf = (r == r->main) ? 1: 0;
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
244 b->last_in_chain = 1;
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
245
356
b743d290eb3b nginx 0.6.22
Igor Sysoev <http://sysoev.ru>
parents: 332
diff changeset
246 b->file->fd = of.fd;
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
247 b->file->name = path;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 b->file->log = log;
406
79c5df00501e nginx 0.7.15
Igor Sysoev <http://sysoev.ru>
parents: 398
diff changeset
249 b->file->directio = of.is_directio;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 out.buf = b;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 out.next = NULL;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254 return ngx_http_output_filter(r, &out);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
258 static ngx_int_t
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 194
diff changeset
259 ngx_http_static_init(ngx_conf_t *cf)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261 ngx_http_handler_pt *h;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262 ngx_http_core_main_conf_t *cmcf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 194
diff changeset
264 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
265
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 if (h == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 return NGX_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 *h = ngx_http_static_handler;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 return NGX_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 }