annotate src/http/modules/ngx_http_gzip_static_module.c @ 664:f5b859b2f097 NGINX_1_1_16

nginx 1.1.16 *) Change: the simultaneous subrequest limit has been raised to 200. *) Feature: the "from" parameter of the "disable_symlinks" directive. *) Feature: the "return" and "error_page" directives can be used to return 307 redirections. *) Bugfix: a segmentation fault might occur in a worker process if the "resolver" directive was used and there was no "error_log" directive specified at global level. Thanks to Roman Arutyunyan. *) Bugfix: a segmentation fault might occur in a worker process if the "proxy_http_version 1.1" or "fastcgi_keep_conn on" directives were used. *) Bugfix: memory leaks. Thanks to Lanshun Zhou. *) Bugfix: in the "disable_symlinks" directive. *) Bugfix: on ZFS filesystem disk cache size might be calculated incorrectly; the bug had appeared in 1.0.1. *) Bugfix: nginx could not be built by the icc 12.1 compiler. *) Bugfix: nginx could not be built by gcc on Solaris; the bug had appeared in 1.1.15.
author Igor Sysoev <http://sysoev.ru>
date Wed, 29 Feb 2012 00:00:00 +0400
parents e5fa0a4a7d27
children 4dcaf40cc702
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
660
d0f7a625f27c nginx 1.1.14
Igor Sysoev <http://sysoev.ru>
parents: 572
diff changeset
4 * Copyright (C) Nginx, Inc.
358
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 typedef struct {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 ngx_flag_t enable;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 } ngx_http_gzip_static_conf_t;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18 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
19 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
20 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
21 void *child);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 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
23
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 static ngx_command_t ngx_http_gzip_static_commands[] = {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 { ngx_string("gzip_static"),
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 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
29 ngx_conf_set_flag_slot,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 NGX_HTTP_LOC_CONF_OFFSET,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 offsetof(ngx_http_gzip_static_conf_t, enable),
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 NULL },
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 ngx_null_command
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 ngx_http_module_t ngx_http_gzip_static_module_ctx = {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 NULL, /* preconfiguration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 ngx_http_gzip_static_init, /* postconfiguration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 NULL, /* create main configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 NULL, /* init main configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 NULL, /* create server configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 NULL, /* merge server configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 ngx_http_gzip_static_create_conf, /* create location configuration */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 ngx_http_gzip_static_merge_conf /* merge location configuration */
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 ngx_module_t ngx_http_gzip_static_module = {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 NGX_MODULE_V1,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 &ngx_http_gzip_static_module_ctx, /* module context */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 ngx_http_gzip_static_commands, /* module directives */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 NGX_HTTP_MODULE, /* module type */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 NULL, /* init master */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 NULL, /* init module */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 NULL, /* init process */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 NULL, /* init thread */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 NULL, /* exit thread */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 NULL, /* exit process */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 NULL, /* exit master */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 NGX_MODULE_V1_PADDING
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 static ngx_int_t
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 ngx_http_gzip_static_handler(ngx_http_request_t *r)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 u_char *p;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 size_t root;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 ngx_str_t path;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 ngx_int_t rc;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 ngx_uint_t level;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 ngx_log_t *log;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 ngx_buf_t *b;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 ngx_chain_t out;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 ngx_table_elt_t *h;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 ngx_open_file_info_t of;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 ngx_http_core_loc_conf_t *clcf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 ngx_http_gzip_static_conf_t *gzcf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
86 return NGX_DECLINED;
358
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 if (r->uri.data[r->uri.len - 1] == '/') {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90 return NGX_DECLINED;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 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
94
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
95 if (!gzcf->enable) {
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
96 return NGX_DECLINED;
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
97 }
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
98
546
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
99 rc = ngx_http_gzip_ok(r);
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
100
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
101 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
102
546
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
103 if (!clcf->gzip_vary && rc != NGX_OK) {
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 return NGX_DECLINED;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107 log = r->connection->log;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 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
110 if (p == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 *p++ = '.';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 *p++ = 'g';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 *p++ = 'z';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 *p = '\0';
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 path.len = p - path.data;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 "http filename: \"%s\"", path.data);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123
384
12defd37f578 nginx 0.7.4
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
124 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
12defd37f578 nginx 0.7.4
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
125
532
f7ec98e3caeb nginx 0.8.18
Igor Sysoev <http://sysoev.ru>
parents: 528
diff changeset
126 of.read_ahead = clcf->read_ahead;
390
0b6053502c55 nginx 0.7.7
Igor Sysoev <http://sysoev.ru>
parents: 388
diff changeset
127 of.directio = clcf->directio;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 of.valid = clcf->open_file_cache_valid;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 of.min_uses = clcf->open_file_cache_min_uses;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 of.errors = clcf->open_file_cache_errors;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 of.events = clcf->open_file_cache_events;
664
f5b859b2f097 nginx 1.1.16
Igor Sysoev <http://sysoev.ru>
parents: 662
diff changeset
132
f5b859b2f097 nginx 1.1.16
Igor Sysoev <http://sysoev.ru>
parents: 662
diff changeset
133 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) {
f5b859b2f097 nginx 1.1.16
Igor Sysoev <http://sysoev.ru>
parents: 662
diff changeset
134 return NGX_HTTP_INTERNAL_SERVER_ERROR;
f5b859b2f097 nginx 1.1.16
Igor Sysoev <http://sysoev.ru>
parents: 662
diff changeset
135 }
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
137 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
138 != NGX_OK)
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
139 {
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 switch (of.err) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142 case 0:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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_ENOENT:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 case NGX_ENOTDIR:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 case NGX_ENAMETOOLONG:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149 return NGX_DECLINED;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 case NGX_EACCES:
662
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
152 #if (NGX_HAVE_OPENAT)
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
153 case NGX_EMLINK:
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
154 case NGX_ELOOP:
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
155 #endif
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157 level = NGX_LOG_ERR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 break;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 default:
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162 level = NGX_LOG_CRIT;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163 break;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166 ngx_log_error(level, log, of.err,
482
392c16f2d858 nginx 0.7.53
Igor Sysoev <http://sysoev.ru>
parents: 480
diff changeset
167 "%s \"%s\" failed", of.failed, path.data);
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168
362
54fad6c4b555 nginx 0.6.25
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
169 return NGX_DECLINED;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171
546
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
172 r->gzip_vary = 1;
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
173
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
174 if (rc != NGX_OK) {
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
175 return NGX_DECLINED;
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
176 }
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 532
diff changeset
177
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178 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
179
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180 if (of.is_dir) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir");
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 return NGX_DECLINED;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 #if !(NGX_WIN32) /* the not regular files are probably Unix specific */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
187 if (!of.is_file) {
568
566e105a89f1 nginx 0.8.36
Igor Sysoev <http://sysoev.ru>
parents: 546
diff changeset
188 ngx_log_error(NGX_LOG_CRIT, log, 0,
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 "\"%s\" is not a regular file", path.data);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 return NGX_HTTP_NOT_FOUND;
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 #endif
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
438
ce4f9ff90bfa nginx 0.7.31
Igor Sysoev <http://sysoev.ru>
parents: 406
diff changeset
196 r->root_tested = !r->error_page;
388
6de24473fa70 nginx 0.7.6
Igor Sysoev <http://sysoev.ru>
parents: 384
diff changeset
197
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198 rc = ngx_http_discard_request_body(r);
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 (rc != NGX_OK) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 return rc;
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 log->action = "sending response to client";
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 r->headers_out.status = NGX_HTTP_OK;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 r->headers_out.content_length_n = of.size;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208 r->headers_out.last_modified_time = of.mtime;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 if (ngx_http_set_content_type(r) != NGX_OK) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 h = ngx_list_push(&r->headers_out.headers);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 if (h == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216 return NGX_ERROR;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 h->hash = 1;
570
8246d8a2c2be nginx 0.8.37
Igor Sysoev <http://sysoev.ru>
parents: 568
diff changeset
220 ngx_str_set(&h->key, "Content-Encoding");
8246d8a2c2be nginx 0.8.37
Igor Sysoev <http://sysoev.ru>
parents: 568
diff changeset
221 ngx_str_set(&h->value, "gzip");
8246d8a2c2be nginx 0.8.37
Igor Sysoev <http://sysoev.ru>
parents: 568
diff changeset
222 r->headers_out.content_encoding = h;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223
494
499474178a11 nginx 0.7.59
Igor Sysoev <http://sysoev.ru>
parents: 482
diff changeset
224 r->ignore_content_encoding = 1;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226 /* we need to allocate all before the header would be sent */
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 if (b == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 if (b->file == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 return NGX_HTTP_INTERNAL_SERVER_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 rc = ngx_http_send_header(r);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241 return rc;
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
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 b->file_pos = 0;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 b->file_last = of.size;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247 b->in_file = b->file_last ? 1 : 0;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 b->last_buf = 1;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 b->last_in_chain = 1;
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 b->file->fd = of.fd;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 b->file->name = path;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 b->file->log = log;
406
79c5df00501e nginx 0.7.15
Igor Sysoev <http://sysoev.ru>
parents: 390
diff changeset
254 b->file->directio = of.is_directio;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256 out.buf = b;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 out.next = NULL;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 return ngx_http_output_filter(r, &out);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 static void *
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264 ngx_http_gzip_static_create_conf(ngx_conf_t *cf)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266 ngx_http_gzip_static_conf_t *conf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 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
269 if (conf == NULL) {
496
f39b9e29530d nginx 0.8.0
Igor Sysoev <http://sysoev.ru>
parents: 494
diff changeset
270 return NULL;
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 conf->enable = NGX_CONF_UNSET;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 return conf;
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
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 static char *
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 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
281 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 ngx_http_gzip_static_conf_t *prev = parent;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 ngx_http_gzip_static_conf_t *conf = child;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 ngx_conf_merge_value(conf->enable, prev->enable, 0);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 return NGX_CONF_OK;
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
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 static ngx_int_t
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292 ngx_http_gzip_static_init(ngx_conf_t *cf)
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 ngx_http_handler_pt *h;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295 ngx_http_core_main_conf_t *cmcf;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 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
298
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300 if (h == NULL) {
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
301 return NGX_ERROR;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 }
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304 *h = ngx_http_gzip_static_handler;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 return NGX_OK;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307 }