annotate src/http/modules/ngx_http_gzip_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 b9fdcaf2062b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 typedef struct {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 ngx_flag_t enable;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 } ngx_http_gzip_static_conf_t;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 static ngx_int_t ngx_http_gzip_static_handler(ngx_http_request_t *r);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18 static void *ngx_http_gzip_static_create_conf(ngx_conf_t *cf);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 static char *ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 void *child);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 static ngx_int_t ngx_http_gzip_static_init(ngx_conf_t *cf);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 static ngx_command_t ngx_http_gzip_static_commands[] = {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 { ngx_string("gzip_static"),
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 ngx_conf_set_flag_slot,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 NGX_HTTP_LOC_CONF_OFFSET,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 offsetof(ngx_http_gzip_static_conf_t, enable),
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 NULL },
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 ngx_null_command
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 };
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 ngx_http_module_t ngx_http_gzip_static_module_ctx = {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 NULL, /* preconfiguration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 ngx_http_gzip_static_init, /* postconfiguration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 NULL, /* create main configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 NULL, /* init main configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 NULL, /* create server configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 NULL, /* merge server configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 ngx_http_gzip_static_create_conf, /* create location configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 ngx_http_gzip_static_merge_conf /* merge location configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 };
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 ngx_module_t ngx_http_gzip_static_module = {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 NGX_MODULE_V1,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 &ngx_http_gzip_static_module_ctx, /* module context */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 ngx_http_gzip_static_commands, /* module directives */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 NGX_HTTP_MODULE, /* module type */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 NULL, /* init master */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 NULL, /* init module */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 NULL, /* init process */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 NULL, /* init thread */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 NULL, /* exit thread */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 NULL, /* exit process */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 NULL, /* exit master */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 NGX_MODULE_V1_PADDING
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 };
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 static ngx_int_t
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 ngx_http_gzip_static_handler(ngx_http_request_t *r)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 u_char *p;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 size_t root;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 ngx_str_t path;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 ngx_int_t rc;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 ngx_uint_t level;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 ngx_log_t *log;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 ngx_buf_t *b;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 ngx_chain_t out;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 ngx_table_elt_t *h;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 ngx_open_file_info_t of;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 ngx_http_core_loc_conf_t *clcf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 ngx_http_gzip_static_conf_t *gzcf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
85 return NGX_DECLINED;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 if (r->uri.data[r->uri.len - 1] == '/') {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 return NGX_DECLINED;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 gzcf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_static_module);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93
502
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
94 if (!gzcf->enable) {
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
95 return NGX_DECLINED;
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
96 }
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
97
504
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
98 rc = ngx_http_gzip_ok(r);
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
99
502
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
100 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
101
504
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
102 if (!clcf->gzip_vary && rc != NGX_OK) {
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 return NGX_DECLINED;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 log = r->connection->log;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 p = ngx_http_map_uri_to_path(r, &path, &root, sizeof(".gz") - 1);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 if (p == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 *p++ = '.';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 *p++ = 'g';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 *p++ = 'z';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 *p = '\0';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 path.len = p - path.data;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 "http filename: \"%s\"", path.data);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122
384
12defd37f578 nginx 0.7.4
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
123 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
12defd37f578 nginx 0.7.4
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
124
390
0b6053502c55 nginx 0.7.7
Igor Sysoev <http://sysoev.ru>
parents: 388
diff changeset
125 of.directio = clcf->directio;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 of.valid = clcf->open_file_cache_valid;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 of.min_uses = clcf->open_file_cache_min_uses;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 of.errors = clcf->open_file_cache_errors;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 of.events = clcf->open_file_cache_events;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
131 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
132 != NGX_OK)
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
133 {
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 switch (of.err) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 case 0:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 case NGX_ENOENT:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 case NGX_ENOTDIR:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 case NGX_ENAMETOOLONG:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 return NGX_DECLINED;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 case NGX_EACCES:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 level = NGX_LOG_ERR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 break;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 default:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 level = NGX_LOG_CRIT;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 break;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 ngx_log_error(level, log, of.err,
482
392c16f2d858 nginx 0.7.53
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
157 "%s \"%s\" failed", of.failed, path.data);
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
159 return NGX_DECLINED;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161
506
b9fdcaf2062b nginx 0.7.65
Igor Sysoev <http://sysoev.ru>
parents: 504
diff changeset
162 r->gzip_vary = 1;
b9fdcaf2062b nginx 0.7.65
Igor Sysoev <http://sysoev.ru>
parents: 504
diff changeset
163
504
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
164 if (rc != NGX_OK) {
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
165 return NGX_DECLINED;
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
166 }
706fef7f4dcc nginx 0.7.64
Igor Sysoev <http://sysoev.ru>
parents: 502
diff changeset
167
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 if (of.is_dir) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir");
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 return NGX_DECLINED;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175 #if !(NGX_WIN32) /* the not regular files are probably Unix specific */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177 if (!of.is_file) {
508
68c0ae0a4959 nginx 0.7.66
Igor Sysoev <http://sysoev.ru>
parents: 506
diff changeset
178 ngx_log_error(NGX_LOG_CRIT, log, 0,
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179 "\"%s\" is not a regular file", path.data);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 return NGX_HTTP_NOT_FOUND;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 #endif
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185
438
ce4f9ff90bfa nginx 0.7.31
Igor Sysoev <http://sysoev.ru>
parents: 406
diff changeset
186 r->root_tested = !r->error_page;
388
6de24473fa70 nginx 0.7.6
Igor Sysoev <http://sysoev.ru>
parents: 384
diff changeset
187
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188 rc = ngx_http_discard_request_body(r);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190 if (rc != NGX_OK) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 return rc;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194 log->action = "sending response to client";
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196 r->headers_out.status = NGX_HTTP_OK;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197 r->headers_out.content_length_n = of.size;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198 r->headers_out.last_modified_time = of.mtime;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 if (ngx_http_set_content_type(r) != NGX_OK) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204 h = ngx_list_push(&r->headers_out.headers);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205 if (h == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 return NGX_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209 h->hash = 1;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 h->key.len = sizeof("Content-Encoding") - 1;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 h->key.data = (u_char *) "Content-Encoding";
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 h->value.len = sizeof("gzip") - 1;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 h->value.data = (u_char *) "gzip";
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 r->headers_out.content_encoding = h;
494
499474178a11 nginx 0.7.59
Igor Sysoev <http://sysoev.ru>
parents: 482
diff changeset
216 r->ignore_content_encoding = 1;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
217
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218 /* we need to allocate all before the header would be sent */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 if (b == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226 if (b->file == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 rc = ngx_http_send_header(r);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 return rc;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 b->file_pos = 0;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 b->file_last = of.size;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 b->in_file = b->file_last ? 1 : 0;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 b->last_buf = 1;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241 b->last_in_chain = 1;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
242
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243 b->file->fd = of.fd;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 b->file->name = path;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 b->file->log = log;
406
79c5df00501e nginx 0.7.15
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
246 b->file->directio = of.is_directio;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 out.buf = b;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 out.next = NULL;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 return ngx_http_output_filter(r, &out);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 static void *
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256 ngx_http_gzip_static_create_conf(ngx_conf_t *cf)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 ngx_http_gzip_static_conf_t *conf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 conf = ngx_palloc(cf->pool, sizeof(ngx_http_gzip_static_conf_t));
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261 if (conf == NULL) {
502
89dc5654117c nginx 0.7.63
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
262 return NULL;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 conf->enable = NGX_CONF_UNSET;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 return conf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 static char *
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, void *child)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 ngx_http_gzip_static_conf_t *prev = parent;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 ngx_http_gzip_static_conf_t *conf = child;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 ngx_conf_merge_value(conf->enable, prev->enable, 0);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279 return NGX_CONF_OK;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 static ngx_int_t
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284 ngx_http_gzip_static_init(ngx_conf_t *cf)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 ngx_http_handler_pt *h;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 ngx_http_core_main_conf_t *cmcf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292 if (h == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 return NGX_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 *h = ngx_http_gzip_static_handler;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 return NGX_OK;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299 }