576
|
1
|
|
2 /*
|
|
3 * Copyright (C) Unbit S.a.s. 2009-2010
|
|
4 * Copyright (C) 2008 Manlio Perillo (manlio.perillo@gmail.com)
|
|
5 * Copyright (C) Igor Sysoev
|
644
|
6 * Copyright (C) Nginx, Inc.
|
576
|
7 */
|
|
8
|
|
9
|
|
10 #include <ngx_config.h>
|
|
11 #include <ngx_core.h>
|
|
12 #include <ngx_http.h>
|
|
13
|
|
14
|
|
15 typedef struct {
|
|
16 ngx_http_upstream_conf_t upstream;
|
|
17
|
|
18 ngx_array_t *flushes;
|
|
19 ngx_array_t *params_len;
|
|
20 ngx_array_t *params;
|
|
21 ngx_array_t *params_source;
|
|
22
|
|
23 ngx_hash_t headers_hash;
|
|
24 ngx_uint_t header_params;
|
|
25
|
|
26 ngx_array_t *uwsgi_lengths;
|
|
27 ngx_array_t *uwsgi_values;
|
|
28
|
|
29 #if (NGX_HTTP_CACHE)
|
|
30 ngx_http_complex_value_t cache_key;
|
|
31 #endif
|
|
32
|
|
33 ngx_str_t uwsgi_string;
|
|
34
|
|
35 ngx_uint_t modifier1;
|
|
36 ngx_uint_t modifier2;
|
|
37 } ngx_http_uwsgi_loc_conf_t;
|
|
38
|
|
39
|
|
40 static ngx_int_t ngx_http_uwsgi_eval(ngx_http_request_t *r,
|
|
41 ngx_http_uwsgi_loc_conf_t *uwcf);
|
|
42 static ngx_int_t ngx_http_uwsgi_create_request(ngx_http_request_t *r);
|
|
43 static ngx_int_t ngx_http_uwsgi_reinit_request(ngx_http_request_t *r);
|
|
44 static ngx_int_t ngx_http_uwsgi_process_status_line(ngx_http_request_t *r);
|
|
45 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r);
|
|
46 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r);
|
|
47 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r);
|
|
48 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r,
|
|
49 ngx_int_t rc);
|
|
50
|
|
51 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf);
|
|
52 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
|
|
53 void *child);
|
642
|
54 static ngx_int_t ngx_http_uwsgi_merge_params(ngx_conf_t *cf,
|
|
55 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_loc_conf_t *prev);
|
576
|
56
|
|
57 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
58 void *conf);
|
|
59 static char *ngx_http_uwsgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
60 void *conf);
|
|
61
|
|
62 #if (NGX_HTTP_CACHE)
|
|
63 static ngx_int_t ngx_http_uwsgi_create_key(ngx_http_request_t *r);
|
|
64 static char *ngx_http_uwsgi_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
65 void *conf);
|
|
66 static char *ngx_http_uwsgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
67 void *conf);
|
|
68 #endif
|
|
69
|
|
70
|
|
71 static ngx_conf_num_bounds_t ngx_http_uwsgi_modifier_bounds = {
|
|
72 ngx_conf_check_num_bounds, 0, 255
|
|
73 };
|
|
74
|
|
75
|
|
76 static ngx_conf_bitmask_t ngx_http_uwsgi_next_upstream_masks[] = {
|
|
77 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
|
|
78 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
|
|
79 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
|
|
80 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
|
|
81 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
|
|
82 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
|
|
83 { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
|
|
84 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
|
|
85 { ngx_null_string, 0 }
|
|
86 };
|
|
87
|
|
88
|
|
89 ngx_module_t ngx_http_uwsgi_module;
|
|
90
|
|
91
|
|
92 static ngx_command_t ngx_http_uwsgi_commands[] = {
|
|
93
|
|
94 { ngx_string("uwsgi_pass"),
|
|
95 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
|
96 ngx_http_uwsgi_pass,
|
|
97 NGX_HTTP_LOC_CONF_OFFSET,
|
|
98 0,
|
|
99 NULL },
|
|
100
|
|
101 { ngx_string("uwsgi_modifier1"),
|
|
102 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
103 ngx_conf_set_num_slot,
|
|
104 NGX_HTTP_LOC_CONF_OFFSET,
|
|
105 offsetof(ngx_http_uwsgi_loc_conf_t, modifier1),
|
|
106 &ngx_http_uwsgi_modifier_bounds },
|
|
107
|
|
108 { ngx_string("uwsgi_modifier2"),
|
|
109 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
110 ngx_conf_set_num_slot,
|
|
111 NGX_HTTP_LOC_CONF_OFFSET,
|
|
112 offsetof(ngx_http_uwsgi_loc_conf_t, modifier2),
|
|
113 &ngx_http_uwsgi_modifier_bounds },
|
|
114
|
|
115 { ngx_string("uwsgi_store"),
|
|
116 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
117 ngx_http_uwsgi_store,
|
|
118 NGX_HTTP_LOC_CONF_OFFSET,
|
|
119 0,
|
|
120 NULL },
|
|
121
|
|
122 { ngx_string("uwsgi_store_access"),
|
|
123 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
|
|
124 ngx_conf_set_access_slot,
|
|
125 NGX_HTTP_LOC_CONF_OFFSET,
|
|
126 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.store_access),
|
|
127 NULL },
|
|
128
|
638
|
129 { ngx_string("uwsgi_buffering"),
|
|
130 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
131 ngx_conf_set_flag_slot,
|
|
132 NGX_HTTP_LOC_CONF_OFFSET,
|
|
133 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.buffering),
|
|
134 NULL },
|
|
135
|
576
|
136 { ngx_string("uwsgi_ignore_client_abort"),
|
|
137 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
138 ngx_conf_set_flag_slot,
|
|
139 NGX_HTTP_LOC_CONF_OFFSET,
|
|
140 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.ignore_client_abort),
|
|
141 NULL },
|
|
142
|
|
143 { ngx_string("uwsgi_bind"),
|
|
144 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
145 ngx_http_upstream_bind_set_slot,
|
|
146 NGX_HTTP_LOC_CONF_OFFSET,
|
|
147 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.local),
|
|
148 NULL },
|
|
149
|
|
150 { ngx_string("uwsgi_connect_timeout"),
|
|
151 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
152 ngx_conf_set_msec_slot,
|
|
153 NGX_HTTP_LOC_CONF_OFFSET,
|
|
154 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.connect_timeout),
|
|
155 NULL },
|
|
156
|
|
157 { ngx_string("uwsgi_send_timeout"),
|
|
158 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
159 ngx_conf_set_msec_slot,
|
|
160 NGX_HTTP_LOC_CONF_OFFSET,
|
|
161 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.send_timeout),
|
|
162 NULL },
|
|
163
|
|
164 { ngx_string("uwsgi_buffer_size"),
|
|
165 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
166 ngx_conf_set_size_slot,
|
|
167 NGX_HTTP_LOC_CONF_OFFSET,
|
|
168 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.buffer_size),
|
|
169 NULL },
|
|
170
|
|
171 { ngx_string("uwsgi_pass_request_headers"),
|
|
172 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
173 ngx_conf_set_flag_slot,
|
|
174 NGX_HTTP_LOC_CONF_OFFSET,
|
|
175 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.pass_request_headers),
|
|
176 NULL },
|
|
177
|
|
178 { ngx_string("uwsgi_pass_request_body"),
|
|
179 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
180 ngx_conf_set_flag_slot,
|
|
181 NGX_HTTP_LOC_CONF_OFFSET,
|
|
182 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.pass_request_body),
|
|
183 NULL },
|
|
184
|
|
185 { ngx_string("uwsgi_intercept_errors"),
|
|
186 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
187 ngx_conf_set_flag_slot,
|
|
188 NGX_HTTP_LOC_CONF_OFFSET,
|
|
189 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.intercept_errors),
|
|
190 NULL },
|
|
191
|
|
192 { ngx_string("uwsgi_read_timeout"),
|
|
193 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
194 ngx_conf_set_msec_slot,
|
|
195 NGX_HTTP_LOC_CONF_OFFSET,
|
|
196 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.read_timeout),
|
|
197 NULL },
|
|
198
|
|
199 { ngx_string("uwsgi_buffers"),
|
|
200 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
201 ngx_conf_set_bufs_slot,
|
|
202 NGX_HTTP_LOC_CONF_OFFSET,
|
|
203 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.bufs),
|
|
204 NULL },
|
|
205
|
|
206 { ngx_string("uwsgi_busy_buffers_size"),
|
|
207 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
208 ngx_conf_set_size_slot,
|
|
209 NGX_HTTP_LOC_CONF_OFFSET,
|
|
210 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.busy_buffers_size_conf),
|
|
211 NULL },
|
|
212
|
|
213 #if (NGX_HTTP_CACHE)
|
|
214
|
|
215 { ngx_string("uwsgi_cache"),
|
592
|
216 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
576
|
217 ngx_http_uwsgi_cache,
|
|
218 NGX_HTTP_LOC_CONF_OFFSET,
|
|
219 0,
|
|
220 NULL },
|
|
221
|
|
222 { ngx_string("uwsgi_cache_key"),
|
592
|
223 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
576
|
224 ngx_http_uwsgi_cache_key,
|
|
225 NGX_HTTP_LOC_CONF_OFFSET,
|
|
226 0,
|
|
227 NULL },
|
|
228
|
|
229 { ngx_string("uwsgi_cache_path"),
|
|
230 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
|
|
231 ngx_http_file_cache_set_slot,
|
|
232 0,
|
|
233 0,
|
|
234 &ngx_http_uwsgi_module },
|
|
235
|
588
|
236 { ngx_string("uwsgi_cache_bypass"),
|
|
237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
238 ngx_http_set_predicate_slot,
|
|
239 NGX_HTTP_LOC_CONF_OFFSET,
|
|
240 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.cache_bypass),
|
|
241 NULL },
|
|
242
|
576
|
243 { ngx_string("uwsgi_no_cache"),
|
|
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
588
|
245 ngx_http_set_predicate_slot,
|
576
|
246 NGX_HTTP_LOC_CONF_OFFSET,
|
|
247 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.no_cache),
|
|
248 NULL },
|
|
249
|
|
250 { ngx_string("uwsgi_cache_valid"),
|
|
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
252 ngx_http_file_cache_valid_set_slot,
|
|
253 NGX_HTTP_LOC_CONF_OFFSET,
|
|
254 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.cache_valid),
|
|
255 NULL },
|
|
256
|
|
257 { ngx_string("uwsgi_cache_min_uses"),
|
|
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
259 ngx_conf_set_num_slot,
|
|
260 NGX_HTTP_LOC_CONF_OFFSET,
|
|
261 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.cache_min_uses),
|
|
262 NULL },
|
|
263
|
|
264 { ngx_string("uwsgi_cache_use_stale"),
|
|
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
266 ngx_conf_set_bitmask_slot,
|
|
267 NGX_HTTP_LOC_CONF_OFFSET,
|
|
268 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.cache_use_stale),
|
|
269 &ngx_http_uwsgi_next_upstream_masks },
|
|
270
|
|
271 { ngx_string("uwsgi_cache_methods"),
|
|
272 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
273 ngx_conf_set_bitmask_slot,
|
|
274 NGX_HTTP_LOC_CONF_OFFSET,
|
|
275 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.cache_methods),
|
|
276 &ngx_http_upstream_cache_method_mask },
|
|
277
|
|
278 #endif
|
|
279
|
|
280 { ngx_string("uwsgi_temp_path"),
|
|
281 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
282 ngx_conf_set_path_slot,
|
|
283 NGX_HTTP_LOC_CONF_OFFSET,
|
|
284 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.temp_path),
|
|
285 NULL },
|
|
286
|
|
287 { ngx_string("uwsgi_max_temp_file_size"),
|
|
288 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
289 ngx_conf_set_size_slot,
|
|
290 NGX_HTTP_LOC_CONF_OFFSET,
|
|
291 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.max_temp_file_size_conf),
|
|
292 NULL },
|
|
293
|
|
294 { ngx_string("uwsgi_temp_file_write_size"),
|
|
295 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
296 ngx_conf_set_size_slot,
|
|
297 NGX_HTTP_LOC_CONF_OFFSET,
|
|
298 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.temp_file_write_size_conf),
|
|
299 NULL },
|
|
300
|
|
301 { ngx_string("uwsgi_next_upstream"),
|
|
302 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
303 ngx_conf_set_bitmask_slot,
|
|
304 NGX_HTTP_LOC_CONF_OFFSET,
|
|
305 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.next_upstream),
|
|
306 &ngx_http_uwsgi_next_upstream_masks },
|
|
307
|
|
308 { ngx_string("uwsgi_param"),
|
|
309 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
310 ngx_conf_set_keyval_slot,
|
|
311 NGX_HTTP_LOC_CONF_OFFSET,
|
|
312 offsetof(ngx_http_uwsgi_loc_conf_t, params_source),
|
|
313 NULL },
|
|
314
|
|
315 { ngx_string("uwsgi_string"),
|
|
316 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
317 ngx_conf_set_str_slot,
|
|
318 NGX_HTTP_LOC_CONF_OFFSET,
|
|
319 offsetof(ngx_http_uwsgi_loc_conf_t, uwsgi_string),
|
|
320 NULL },
|
|
321
|
|
322 { ngx_string("uwsgi_pass_header"),
|
592
|
323 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
576
|
324 ngx_conf_set_str_array_slot,
|
|
325 NGX_HTTP_LOC_CONF_OFFSET,
|
|
326 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.pass_headers),
|
|
327 NULL },
|
|
328
|
|
329 { ngx_string("uwsgi_hide_header"),
|
592
|
330 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
576
|
331 ngx_conf_set_str_array_slot,
|
|
332 NGX_HTTP_LOC_CONF_OFFSET,
|
|
333 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.hide_headers),
|
|
334 NULL },
|
|
335
|
|
336 { ngx_string("uwsgi_ignore_headers"),
|
|
337 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
338 ngx_conf_set_bitmask_slot,
|
|
339 NGX_HTTP_LOC_CONF_OFFSET,
|
|
340 offsetof(ngx_http_uwsgi_loc_conf_t, upstream.ignore_headers),
|
584
|
341 &ngx_http_upstream_ignore_headers_masks },
|
576
|
342
|
|
343 ngx_null_command
|
|
344 };
|
|
345
|
|
346
|
|
347 static ngx_http_module_t ngx_http_uwsgi_module_ctx = {
|
|
348 NULL, /* preconfiguration */
|
|
349 NULL, /* postconfiguration */
|
|
350
|
|
351 NULL, /* create main configuration */
|
|
352 NULL, /* init main configuration */
|
|
353
|
|
354 NULL, /* create server configuration */
|
|
355 NULL, /* merge server configuration */
|
|
356
|
|
357 ngx_http_uwsgi_create_loc_conf, /* create location configuration */
|
|
358 ngx_http_uwsgi_merge_loc_conf /* merge location configuration */
|
|
359 };
|
|
360
|
|
361
|
|
362 ngx_module_t ngx_http_uwsgi_module = {
|
|
363 NGX_MODULE_V1,
|
|
364 &ngx_http_uwsgi_module_ctx, /* module context */
|
|
365 ngx_http_uwsgi_commands, /* module directives */
|
|
366 NGX_HTTP_MODULE, /* module type */
|
|
367 NULL, /* init master */
|
|
368 NULL, /* init module */
|
|
369 NULL, /* init process */
|
|
370 NULL, /* init thread */
|
|
371 NULL, /* exit thread */
|
|
372 NULL, /* exit process */
|
|
373 NULL, /* exit master */
|
|
374 NGX_MODULE_V1_PADDING
|
|
375 };
|
|
376
|
|
377
|
|
378 static ngx_str_t ngx_http_uwsgi_hide_headers[] = {
|
|
379 ngx_string("X-Accel-Expires"),
|
|
380 ngx_string("X-Accel-Redirect"),
|
|
381 ngx_string("X-Accel-Limit-Rate"),
|
|
382 ngx_string("X-Accel-Buffering"),
|
|
383 ngx_string("X-Accel-Charset"),
|
|
384 ngx_null_string
|
|
385 };
|
|
386
|
|
387
|
|
388 #if (NGX_HTTP_CACHE)
|
|
389
|
|
390 static ngx_keyval_t ngx_http_uwsgi_cache_headers[] = {
|
|
391 { ngx_string("HTTP_IF_MODIFIED_SINCE"), ngx_string("") },
|
|
392 { ngx_string("HTTP_IF_UNMODIFIED_SINCE"), ngx_string("") },
|
|
393 { ngx_string("HTTP_IF_NONE_MATCH"), ngx_string("") },
|
|
394 { ngx_string("HTTP_IF_MATCH"), ngx_string("") },
|
|
395 { ngx_string("HTTP_RANGE"), ngx_string("") },
|
|
396 { ngx_string("HTTP_IF_RANGE"), ngx_string("") },
|
|
397 { ngx_null_string, ngx_null_string }
|
|
398 };
|
|
399
|
|
400 #endif
|
|
401
|
|
402
|
|
403 static ngx_path_init_t ngx_http_uwsgi_temp_path = {
|
|
404 ngx_string(NGX_HTTP_UWSGI_TEMP_PATH), { 1, 2, 0 }
|
|
405 };
|
|
406
|
|
407
|
|
408 static ngx_int_t
|
|
409 ngx_http_uwsgi_handler(ngx_http_request_t *r)
|
|
410 {
|
|
411 ngx_int_t rc;
|
580
|
412 ngx_http_status_t *status;
|
576
|
413 ngx_http_upstream_t *u;
|
|
414 ngx_http_uwsgi_loc_conf_t *uwcf;
|
|
415
|
|
416 if (r->subrequest_in_memory) {
|
|
417 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
418 "ngx_http_uwsgi_module does not support "
|
|
419 "subrequests in memory");
|
|
420 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
421 }
|
|
422
|
|
423 if (ngx_http_upstream_create(r) != NGX_OK) {
|
|
424 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
425 }
|
|
426
|
580
|
427 status = ngx_pcalloc(r->pool, sizeof(ngx_http_status_t));
|
|
428 if (status == NULL) {
|
576
|
429 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
430 }
|
|
431
|
580
|
432 ngx_http_set_ctx(r, status, ngx_http_uwsgi_module);
|
576
|
433
|
|
434 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
|
|
435
|
|
436 if (uwcf->uwsgi_lengths) {
|
|
437 if (ngx_http_uwsgi_eval(r, uwcf) != NGX_OK) {
|
|
438 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
439 }
|
|
440 }
|
|
441
|
|
442 u = r->upstream;
|
|
443
|
|
444 ngx_str_set(&u->schema, "uwsgi://");
|
|
445 u->output.tag = (ngx_buf_tag_t) &ngx_http_uwsgi_module;
|
|
446
|
|
447 u->conf = &uwcf->upstream;
|
|
448
|
|
449 #if (NGX_HTTP_CACHE)
|
|
450 u->create_key = ngx_http_uwsgi_create_key;
|
|
451 #endif
|
|
452 u->create_request = ngx_http_uwsgi_create_request;
|
|
453 u->reinit_request = ngx_http_uwsgi_reinit_request;
|
|
454 u->process_header = ngx_http_uwsgi_process_status_line;
|
|
455 u->abort_request = ngx_http_uwsgi_abort_request;
|
|
456 u->finalize_request = ngx_http_uwsgi_finalize_request;
|
|
457
|
638
|
458 u->buffering = uwcf->upstream.buffering;
|
576
|
459
|
|
460 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
|
|
461 if (u->pipe == NULL) {
|
|
462 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
463 }
|
|
464
|
|
465 u->pipe->input_filter = ngx_event_pipe_copy_input_filter;
|
|
466 u->pipe->input_ctx = r;
|
|
467
|
|
468 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
|
|
469
|
|
470 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
|
471 return rc;
|
|
472 }
|
|
473
|
|
474 return NGX_DONE;
|
|
475 }
|
|
476
|
|
477
|
|
478 static ngx_int_t
|
|
479 ngx_http_uwsgi_eval(ngx_http_request_t *r, ngx_http_uwsgi_loc_conf_t * uwcf)
|
|
480 {
|
578
|
481 ngx_url_t url;
|
|
482 ngx_http_upstream_t *u;
|
576
|
483
|
578
|
484 ngx_memzero(&url, sizeof(ngx_url_t));
|
576
|
485
|
578
|
486 if (ngx_http_script_run(r, &url.url, uwcf->uwsgi_lengths->elts, 0,
|
576
|
487 uwcf->uwsgi_values->elts)
|
|
488 == NULL)
|
|
489 {
|
|
490 return NGX_ERROR;
|
|
491 }
|
|
492
|
578
|
493 url.no_resolve = 1;
|
576
|
494
|
578
|
495 if (ngx_parse_url(r->pool, &url) != NGX_OK) {
|
|
496 if (url.err) {
|
576
|
497 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
578
|
498 "%s in upstream \"%V\"", url.err, &url.url);
|
576
|
499 }
|
|
500
|
|
501 return NGX_ERROR;
|
|
502 }
|
|
503
|
578
|
504 u = r->upstream;
|
|
505
|
|
506 u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
|
|
507 if (u->resolved == NULL) {
|
576
|
508 return NGX_ERROR;
|
|
509 }
|
|
510
|
578
|
511 if (url.addrs && url.addrs[0].sockaddr) {
|
|
512 u->resolved->sockaddr = url.addrs[0].sockaddr;
|
|
513 u->resolved->socklen = url.addrs[0].socklen;
|
|
514 u->resolved->naddrs = 1;
|
|
515 u->resolved->host = url.addrs[0].name;
|
576
|
516
|
|
517 } else {
|
578
|
518 u->resolved->host = url.host;
|
|
519 u->resolved->port = url.port;
|
618
|
520 u->resolved->no_port = url.no_port;
|
576
|
521 }
|
|
522
|
|
523 return NGX_OK;
|
|
524 }
|
|
525
|
|
526
|
|
527 #if (NGX_HTTP_CACHE)
|
|
528
|
|
529 static ngx_int_t
|
|
530 ngx_http_uwsgi_create_key(ngx_http_request_t *r)
|
|
531 {
|
|
532 ngx_str_t *key;
|
|
533 ngx_http_uwsgi_loc_conf_t *uwcf;
|
|
534
|
|
535 key = ngx_array_push(&r->cache->keys);
|
|
536 if (key == NULL) {
|
|
537 return NGX_ERROR;
|
|
538 }
|
|
539
|
|
540 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
|
|
541
|
|
542 if (ngx_http_complex_value(r, &uwcf->cache_key, key) != NGX_OK) {
|
|
543 return NGX_ERROR;
|
|
544 }
|
|
545
|
|
546 return NGX_OK;
|
|
547 }
|
|
548
|
|
549 #endif
|
|
550
|
|
551
|
|
552 static ngx_int_t
|
|
553 ngx_http_uwsgi_create_request(ngx_http_request_t *r)
|
|
554 {
|
|
555 u_char ch, *lowcase_key;
|
|
556 size_t key_len, val_len, len, allocated;
|
|
557 ngx_uint_t i, n, hash, header_params;
|
|
558 ngx_buf_t *b;
|
|
559 ngx_chain_t *cl, *body;
|
|
560 ngx_list_part_t *part;
|
|
561 ngx_table_elt_t *header, **ignored;
|
|
562 ngx_http_script_code_pt code;
|
|
563 ngx_http_script_engine_t e, le;
|
|
564 ngx_http_uwsgi_loc_conf_t *uwcf;
|
|
565 ngx_http_script_len_code_pt lcode;
|
|
566
|
|
567 len = 0;
|
|
568 header_params = 0;
|
|
569 ignored = NULL;
|
|
570
|
|
571 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
|
|
572
|
|
573 if (uwcf->params_len) {
|
|
574 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
|
|
575
|
|
576 ngx_http_script_flush_no_cacheable_variables(r, uwcf->flushes);
|
|
577 le.flushed = 1;
|
|
578
|
|
579 le.ip = uwcf->params_len->elts;
|
|
580 le.request = r;
|
|
581
|
|
582 while (*(uintptr_t *) le.ip) {
|
|
583
|
|
584 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
585 key_len = lcode(&le);
|
|
586
|
|
587 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode (&le)) {
|
|
588 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
589 }
|
|
590 le.ip += sizeof(uintptr_t);
|
|
591
|
|
592 len += 2 + key_len + 2 + val_len;
|
|
593 }
|
|
594 }
|
|
595
|
|
596 if (uwcf->upstream.pass_request_headers) {
|
|
597
|
|
598 allocated = 0;
|
|
599 lowcase_key = NULL;
|
|
600
|
|
601 if (uwcf->header_params) {
|
632
|
602 n = 0;
|
|
603 part = &r->headers_in.headers.part;
|
|
604
|
|
605 while (part) {
|
|
606 n += part->nelts;
|
|
607 part = part->next;
|
|
608 }
|
|
609
|
|
610 ignored = ngx_palloc(r->pool, n * sizeof(void *));
|
576
|
611 if (ignored == NULL) {
|
|
612 return NGX_ERROR;
|
|
613 }
|
|
614 }
|
|
615
|
|
616 part = &r->headers_in.headers.part;
|
|
617 header = part->elts;
|
|
618
|
|
619 for (i = 0; /* void */ ; i++) {
|
|
620
|
|
621 if (i >= part->nelts) {
|
|
622 if (part->next == NULL) {
|
|
623 break;
|
|
624 }
|
|
625
|
|
626 part = part->next;
|
|
627 header = part->elts;
|
|
628 i = 0;
|
|
629 }
|
|
630
|
|
631 if (uwcf->header_params) {
|
|
632 if (allocated < header[i].key.len) {
|
|
633 allocated = header[i].key.len + 16;
|
|
634 lowcase_key = ngx_pnalloc(r->pool, allocated);
|
|
635 if (lowcase_key == NULL) {
|
|
636 return NGX_ERROR;
|
|
637 }
|
|
638 }
|
|
639
|
|
640 hash = 0;
|
|
641
|
|
642 for (n = 0; n < header[i].key.len; n++) {
|
|
643 ch = header[i].key.data[n];
|
|
644
|
|
645 if (ch >= 'A' && ch <= 'Z') {
|
|
646 ch |= 0x20;
|
|
647
|
|
648 } else if (ch == '-') {
|
|
649 ch = '_';
|
|
650 }
|
|
651
|
|
652 hash = ngx_hash(hash, ch);
|
|
653 lowcase_key[n] = ch;
|
|
654 }
|
|
655
|
|
656 if (ngx_hash_find(&uwcf->headers_hash, hash, lowcase_key, n)) {
|
|
657 ignored[header_params++] = &header[i];
|
|
658 continue;
|
|
659 }
|
|
660 }
|
|
661
|
|
662 len += 2 + sizeof("HTTP_") - 1 + header[i].key.len
|
|
663 + 2 + header[i].value.len;
|
|
664 }
|
|
665 }
|
|
666
|
|
667 len += uwcf->uwsgi_string.len;
|
|
668
|
|
669 #if 0
|
|
670 /* allow custom uwsgi packet */
|
|
671 if (len > 0 && len < 2) {
|
|
672 ngx_log_error (NGX_LOG_ALERT, r->connection->log, 0,
|
|
673 "uwsgi request is too little: %uz", len);
|
|
674 return NGX_ERROR;
|
|
675 }
|
|
676 #endif
|
|
677
|
|
678 b = ngx_create_temp_buf(r->pool, len + 4);
|
|
679 if (b == NULL) {
|
|
680 return NGX_ERROR;
|
|
681 }
|
|
682
|
|
683 cl = ngx_alloc_chain_link(r->pool);
|
|
684 if (cl == NULL) {
|
|
685 return NGX_ERROR;
|
|
686 }
|
|
687
|
|
688 cl->buf = b;
|
|
689
|
|
690 *b->last++ = (u_char) uwcf->modifier1;
|
|
691 *b->last++ = (u_char) (len & 0xff);
|
|
692 *b->last++ = (u_char) ((len >> 8) & 0xff);
|
|
693 *b->last++ = (u_char) uwcf->modifier2;
|
|
694
|
|
695 if (uwcf->params_len) {
|
|
696 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
|
697
|
|
698 e.ip = uwcf->params->elts;
|
|
699 e.pos = b->last;
|
|
700 e.request = r;
|
|
701 e.flushed = 1;
|
|
702
|
|
703 le.ip = uwcf->params_len->elts;
|
|
704
|
|
705 while (*(uintptr_t *) le.ip) {
|
|
706
|
|
707 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
708 key_len = (u_char) lcode (&le);
|
|
709
|
|
710 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
|
711 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
712 }
|
|
713 le.ip += sizeof(uintptr_t);
|
|
714
|
|
715 *e.pos++ = (u_char) (key_len & 0xff);
|
|
716 *e.pos++ = (u_char) ((key_len >> 8) & 0xff);
|
|
717
|
|
718 code = *(ngx_http_script_code_pt *) e.ip;
|
|
719 code((ngx_http_script_engine_t *) & e);
|
|
720
|
|
721 *e.pos++ = (u_char) (val_len & 0xff);
|
|
722 *e.pos++ = (u_char) ((val_len >> 8) & 0xff);
|
|
723
|
|
724 while (*(uintptr_t *) e.ip) {
|
|
725 code = *(ngx_http_script_code_pt *) e.ip;
|
|
726 code((ngx_http_script_engine_t *) & e);
|
|
727 }
|
|
728
|
|
729 e.ip += sizeof(uintptr_t);
|
|
730
|
|
731 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
732 "uwsgi param: \"%*s: %*s\"",
|
|
733 key_len, e.pos - (key_len + 2 + val_len),
|
|
734 val_len, e.pos - val_len);
|
|
735 }
|
|
736
|
|
737 b->last = e.pos;
|
|
738 }
|
|
739
|
|
740 if (uwcf->upstream.pass_request_headers) {
|
|
741
|
|
742 part = &r->headers_in.headers.part;
|
|
743 header = part->elts;
|
|
744
|
|
745 for (i = 0; /* void */ ; i++) {
|
|
746
|
|
747 if (i >= part->nelts) {
|
|
748 if (part->next == NULL) {
|
|
749 break;
|
|
750 }
|
|
751
|
|
752 part = part->next;
|
|
753 header = part->elts;
|
|
754 i = 0;
|
|
755 }
|
|
756
|
|
757 for (n = 0; n < header_params; n++) {
|
|
758 if (&header[i] == ignored[n]) {
|
|
759 goto next;
|
|
760 }
|
|
761 }
|
|
762
|
|
763 key_len = sizeof("HTTP_") - 1 + header[i].key.len;
|
|
764 *b->last++ = (u_char) (key_len & 0xff);
|
|
765 *b->last++ = (u_char) ((key_len >> 8) & 0xff);
|
|
766
|
|
767 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1);
|
|
768 for (n = 0; n < header[i].key.len; n++) {
|
|
769 ch = header[i].key.data[n];
|
|
770
|
|
771 if (ch >= 'a' && ch <= 'z') {
|
|
772 ch &= ~0x20;
|
|
773
|
|
774 } else if (ch == '-') {
|
|
775 ch = '_';
|
|
776 }
|
|
777
|
|
778 *b->last++ = ch;
|
|
779 }
|
|
780
|
|
781 val_len = header[i].value.len;
|
|
782 *b->last++ = (u_char) (val_len & 0xff);
|
|
783 *b->last++ = (u_char) ((val_len >> 8) & 0xff);
|
|
784 b->last = ngx_copy(b->last, header[i].value.data, val_len);
|
|
785
|
|
786 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
787 "uwsgi param: \"%*s: %*s\"",
|
|
788 key_len, b->last - (key_len + 2 + val_len),
|
|
789 val_len, b->last - val_len);
|
|
790 next:
|
|
791
|
|
792 continue;
|
|
793 }
|
|
794 }
|
|
795
|
|
796 b->last = ngx_copy(b->last, uwcf->uwsgi_string.data,
|
|
797 uwcf->uwsgi_string.len);
|
|
798
|
|
799 if (uwcf->upstream.pass_request_body) {
|
|
800 body = r->upstream->request_bufs;
|
|
801 r->upstream->request_bufs = cl;
|
|
802
|
|
803 while (body) {
|
|
804 b = ngx_alloc_buf(r->pool);
|
|
805 if (b == NULL) {
|
|
806 return NGX_ERROR;
|
|
807 }
|
|
808
|
|
809 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
|
|
810
|
|
811 cl->next = ngx_alloc_chain_link(r->pool);
|
|
812 if (cl->next == NULL) {
|
|
813 return NGX_ERROR;
|
|
814 }
|
|
815
|
|
816 cl = cl->next;
|
|
817 cl->buf = b;
|
|
818
|
|
819 body = body->next;
|
|
820 }
|
|
821
|
|
822 } else {
|
|
823 r->upstream->request_bufs = cl;
|
|
824 }
|
|
825
|
|
826 cl->next = NULL;
|
|
827
|
|
828 return NGX_OK;
|
|
829 }
|
|
830
|
|
831
|
|
832 static ngx_int_t
|
|
833 ngx_http_uwsgi_reinit_request(ngx_http_request_t *r)
|
|
834 {
|
580
|
835 ngx_http_status_t *status;
|
576
|
836
|
580
|
837 status = ngx_http_get_module_ctx(r, ngx_http_uwsgi_module);
|
576
|
838
|
580
|
839 if (status == NULL) {
|
576
|
840 return NGX_OK;
|
|
841 }
|
|
842
|
580
|
843 status->code = 0;
|
|
844 status->count = 0;
|
|
845 status->start = NULL;
|
|
846 status->end = NULL;
|
576
|
847
|
|
848 r->upstream->process_header = ngx_http_uwsgi_process_status_line;
|
|
849
|
|
850 return NGX_OK;
|
|
851 }
|
|
852
|
|
853
|
|
854 static ngx_int_t
|
|
855 ngx_http_uwsgi_process_status_line(ngx_http_request_t *r)
|
|
856 {
|
580
|
857 size_t len;
|
|
858 ngx_int_t rc;
|
|
859 ngx_http_status_t *status;
|
576
|
860 ngx_http_upstream_t *u;
|
|
861
|
580
|
862 status = ngx_http_get_module_ctx(r, ngx_http_uwsgi_module);
|
576
|
863
|
580
|
864 if (status == NULL) {
|
576
|
865 return NGX_ERROR;
|
|
866 }
|
|
867
|
580
|
868 u = r->upstream;
|
|
869
|
|
870 rc = ngx_http_parse_status_line(r, &u->buffer, status);
|
576
|
871
|
|
872 if (rc == NGX_AGAIN) {
|
|
873 return rc;
|
|
874 }
|
|
875
|
580
|
876 if (rc == NGX_ERROR) {
|
|
877 r->http_version = NGX_HTTP_VERSION_9;
|
576
|
878
|
580
|
879 u->process_header = ngx_http_uwsgi_process_header;
|
576
|
880
|
580
|
881 return ngx_http_uwsgi_process_header(r);
|
576
|
882 }
|
|
883
|
|
884 if (u->state) {
|
580
|
885 u->state->status = status->code;
|
576
|
886 }
|
|
887
|
580
|
888 u->headers_in.status_n = status->code;
|
576
|
889
|
580
|
890 len = status->end - status->start;
|
|
891 u->headers_in.status_line.len = len;
|
|
892
|
|
893 u->headers_in.status_line.data = ngx_pnalloc(r->pool, len);
|
576
|
894 if (u->headers_in.status_line.data == NULL) {
|
|
895 return NGX_ERROR;
|
|
896 }
|
|
897
|
580
|
898 ngx_memcpy(u->headers_in.status_line.data, status->start, len);
|
576
|
899
|
|
900 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
901 "http uwsgi status %ui \"%V\"",
|
|
902 u->headers_in.status_n, &u->headers_in.status_line);
|
|
903
|
|
904 u->process_header = ngx_http_uwsgi_process_header;
|
|
905
|
|
906 return ngx_http_uwsgi_process_header(r);
|
|
907 }
|
|
908
|
|
909
|
|
910 static ngx_int_t
|
|
911 ngx_http_uwsgi_process_header(ngx_http_request_t *r)
|
|
912 {
|
580
|
913 ngx_str_t *status_line;
|
|
914 ngx_int_t rc, status;
|
576
|
915 ngx_table_elt_t *h;
|
580
|
916 ngx_http_upstream_t *u;
|
576
|
917 ngx_http_upstream_header_t *hh;
|
|
918 ngx_http_upstream_main_conf_t *umcf;
|
|
919
|
|
920 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
|
921
|
|
922 for ( ;; ) {
|
|
923
|
|
924 rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1);
|
|
925
|
|
926 if (rc == NGX_OK) {
|
|
927
|
|
928 /* a header line has been parsed successfully */
|
|
929
|
|
930 h = ngx_list_push(&r->upstream->headers_in.headers);
|
|
931 if (h == NULL) {
|
|
932 return NGX_ERROR;
|
|
933 }
|
|
934
|
|
935 h->hash = r->header_hash;
|
|
936
|
|
937 h->key.len = r->header_name_end - r->header_name_start;
|
|
938 h->value.len = r->header_end - r->header_start;
|
|
939
|
|
940 h->key.data = ngx_pnalloc(r->pool,
|
|
941 h->key.len + 1 + h->value.len + 1
|
|
942 + h->key.len);
|
|
943 if (h->key.data == NULL) {
|
|
944 return NGX_ERROR;
|
|
945 }
|
|
946
|
|
947 h->value.data = h->key.data + h->key.len + 1;
|
|
948 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;
|
|
949
|
|
950 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);
|
|
951 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);
|
|
952
|
|
953 if (h->key.len == r->lowcase_index) {
|
|
954 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
|
|
955
|
|
956 } else {
|
|
957 ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
|
|
958 }
|
|
959
|
|
960 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
|
|
961 h->lowcase_key, h->key.len);
|
|
962
|
|
963 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
|
|
964 return NGX_ERROR;
|
|
965 }
|
|
966
|
|
967 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
968 "http uwsgi header: \"%V: %V\"", &h->key, &h->value);
|
|
969
|
|
970 continue;
|
|
971 }
|
|
972
|
|
973 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
974
|
|
975 /* a whole header has been parsed successfully */
|
|
976
|
|
977 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
978 "http uwsgi header done");
|
|
979
|
580
|
980 if (r->http_version > NGX_HTTP_VERSION_9) {
|
|
981 return NGX_OK;
|
|
982 }
|
|
983
|
|
984 u = r->upstream;
|
|
985
|
|
986 if (u->headers_in.status) {
|
|
987 status_line = &u->headers_in.status->value;
|
|
988
|
|
989 status = ngx_atoi(status_line->data, 3);
|
|
990 if (status == NGX_ERROR) {
|
|
991 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
992 "upstream sent invalid status \"%V\"",
|
|
993 status_line);
|
|
994 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
995 }
|
|
996
|
|
997 r->http_version = NGX_HTTP_VERSION_10;
|
|
998 u->headers_in.status_n = status;
|
|
999 u->headers_in.status_line = *status_line;
|
|
1000
|
|
1001 } else if (u->headers_in.location) {
|
|
1002 r->http_version = NGX_HTTP_VERSION_10;
|
|
1003 u->headers_in.status_n = 302;
|
|
1004 ngx_str_set(&u->headers_in.status_line,
|
|
1005 "302 Moved Temporarily");
|
|
1006
|
|
1007 } else {
|
|
1008 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1009 "upstream sent neither valid HTTP/1.0 header "
|
|
1010 "nor \"Status\" header line");
|
|
1011 u->headers_in.status_n = 200;
|
|
1012 ngx_str_set(&u->headers_in.status_line, "200 OK");
|
|
1013 }
|
|
1014
|
|
1015 if (u->state) {
|
|
1016 u->state->status = u->headers_in.status_n;
|
|
1017 }
|
|
1018
|
576
|
1019 return NGX_OK;
|
|
1020 }
|
|
1021
|
|
1022 if (rc == NGX_AGAIN) {
|
|
1023 return NGX_AGAIN;
|
|
1024 }
|
|
1025
|
|
1026 /* there was error while a header line parsing */
|
|
1027
|
|
1028 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1029 "upstream sent invalid header");
|
|
1030
|
|
1031 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1032 }
|
|
1033 }
|
|
1034
|
|
1035
|
|
1036 static void
|
|
1037 ngx_http_uwsgi_abort_request(ngx_http_request_t *r)
|
|
1038 {
|
|
1039 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1040 "abort http uwsgi request");
|
|
1041
|
|
1042 return;
|
|
1043 }
|
|
1044
|
|
1045
|
|
1046 static void
|
|
1047 ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
|
1048 {
|
|
1049 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1050 "finalize http uwsgi request");
|
|
1051
|
|
1052 return;
|
|
1053 }
|
|
1054
|
|
1055
|
|
1056 static void *
|
|
1057 ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf)
|
|
1058 {
|
|
1059 ngx_http_uwsgi_loc_conf_t *conf;
|
|
1060
|
|
1061 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uwsgi_loc_conf_t));
|
|
1062 if (conf == NULL) {
|
|
1063 return NULL;
|
|
1064 }
|
|
1065
|
|
1066 conf->modifier1 = NGX_CONF_UNSET_UINT;
|
|
1067 conf->modifier2 = NGX_CONF_UNSET_UINT;
|
|
1068
|
|
1069 conf->upstream.store = NGX_CONF_UNSET;
|
|
1070 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
|
1071 conf->upstream.buffering = NGX_CONF_UNSET;
|
|
1072 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
|
|
1073
|
|
1074 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
|
|
1075 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
|
|
1076 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
|
|
1077
|
|
1078 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
|
|
1079 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
|
|
1080
|
|
1081 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
|
|
1082 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
|
|
1083 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
|
|
1084
|
|
1085 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
|
|
1086 conf->upstream.pass_request_body = NGX_CONF_UNSET;
|
|
1087
|
|
1088 #if (NGX_HTTP_CACHE)
|
|
1089 conf->upstream.cache = NGX_CONF_UNSET_PTR;
|
|
1090 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
|
588
|
1091 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
|
|
1092 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
|
576
|
1093 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
|
|
1094 #endif
|
|
1095
|
|
1096 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
|
|
1097 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
|
|
1098
|
|
1099 conf->upstream.intercept_errors = NGX_CONF_UNSET;
|
|
1100
|
|
1101 /* "uwsgi_cyclic_temp_file" is disabled */
|
|
1102 conf->upstream.cyclic_temp_file = 0;
|
|
1103
|
638
|
1104 conf->upstream.change_buffering = 1;
|
|
1105
|
632
|
1106 ngx_str_set(&conf->upstream.module, "uwsgi");
|
|
1107
|
576
|
1108 return conf;
|
|
1109 }
|
|
1110
|
|
1111
|
|
1112 static char *
|
|
1113 ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
1114 {
|
|
1115 ngx_http_uwsgi_loc_conf_t *prev = parent;
|
|
1116 ngx_http_uwsgi_loc_conf_t *conf = child;
|
|
1117
|
|
1118 size_t size;
|
|
1119 ngx_hash_init_t hash;
|
592
|
1120 ngx_http_core_loc_conf_t *clcf;
|
576
|
1121
|
|
1122 if (conf->upstream.store != 0) {
|
|
1123 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
|
|
1124
|
|
1125 if (conf->upstream.store_lengths == NULL) {
|
|
1126 conf->upstream.store_lengths = prev->upstream.store_lengths;
|
|
1127 conf->upstream.store_values = prev->upstream.store_values;
|
|
1128 }
|
|
1129 }
|
|
1130
|
|
1131 ngx_conf_merge_uint_value(conf->upstream.store_access,
|
|
1132 prev->upstream.store_access, 0600);
|
|
1133
|
|
1134 ngx_conf_merge_value(conf->upstream.buffering,
|
|
1135 prev->upstream.buffering, 1);
|
|
1136
|
|
1137 ngx_conf_merge_value(conf->upstream.ignore_client_abort,
|
|
1138 prev->upstream.ignore_client_abort, 0);
|
|
1139
|
|
1140 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
|
|
1141 prev->upstream.connect_timeout, 60000);
|
|
1142
|
|
1143 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
|
|
1144 prev->upstream.send_timeout, 60000);
|
|
1145
|
|
1146 ngx_conf_merge_msec_value(conf->upstream.read_timeout,
|
|
1147 prev->upstream.read_timeout, 60000);
|
|
1148
|
|
1149 ngx_conf_merge_size_value(conf->upstream.send_lowat,
|
|
1150 prev->upstream.send_lowat, 0);
|
|
1151
|
|
1152 ngx_conf_merge_size_value(conf->upstream.buffer_size,
|
|
1153 prev->upstream.buffer_size,
|
|
1154 (size_t) ngx_pagesize);
|
|
1155
|
|
1156
|
|
1157 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
|
|
1158 8, ngx_pagesize);
|
|
1159
|
|
1160 if (conf->upstream.bufs.num < 2) {
|
|
1161 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1162 "there must be at least 2 \"uwsgi_buffers\"");
|
|
1163 return NGX_CONF_ERROR;
|
|
1164 }
|
|
1165
|
|
1166
|
|
1167 size = conf->upstream.buffer_size;
|
|
1168 if (size < conf->upstream.bufs.size) {
|
|
1169 size = conf->upstream.bufs.size;
|
|
1170 }
|
|
1171
|
|
1172
|
|
1173 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
|
|
1174 prev->upstream.busy_buffers_size_conf,
|
|
1175 NGX_CONF_UNSET_SIZE);
|
|
1176
|
|
1177 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
|
|
1178 conf->upstream.busy_buffers_size = 2 * size;
|
|
1179 } else {
|
|
1180 conf->upstream.busy_buffers_size =
|
|
1181 conf->upstream.busy_buffers_size_conf;
|
|
1182 }
|
|
1183
|
|
1184 if (conf->upstream.busy_buffers_size < size) {
|
|
1185 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1186 "\"uwsgi_busy_buffers_size\" must be equal or bigger "
|
|
1187 "than maximum of the value of \"uwsgi_buffer_size\" and "
|
|
1188 "one of the \"uwsgi_buffers\"");
|
|
1189
|
|
1190 return NGX_CONF_ERROR;
|
|
1191 }
|
|
1192
|
|
1193 if (conf->upstream.busy_buffers_size
|
|
1194 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
|
|
1195 {
|
|
1196 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1197 "\"uwsgi_busy_buffers_size\" must be less than "
|
|
1198 "the size of all \"uwsgi_buffers\" minus one buffer");
|
|
1199
|
|
1200 return NGX_CONF_ERROR;
|
|
1201 }
|
|
1202
|
|
1203
|
|
1204 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
|
|
1205 prev->upstream.temp_file_write_size_conf,
|
|
1206 NGX_CONF_UNSET_SIZE);
|
|
1207
|
|
1208 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
|
|
1209 conf->upstream.temp_file_write_size = 2 * size;
|
|
1210 } else {
|
|
1211 conf->upstream.temp_file_write_size =
|
|
1212 conf->upstream.temp_file_write_size_conf;
|
|
1213 }
|
|
1214
|
|
1215 if (conf->upstream.temp_file_write_size < size) {
|
|
1216 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1217 "\"uwsgi_temp_file_write_size\" must be equal or bigger than "
|
|
1218 "maximum of the value of \"uwsgi_buffer_size\" and "
|
|
1219 "one of the \"uwsgi_buffers\"");
|
|
1220
|
|
1221 return NGX_CONF_ERROR;
|
|
1222 }
|
|
1223
|
|
1224
|
|
1225 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
|
|
1226 prev->upstream.max_temp_file_size_conf,
|
|
1227 NGX_CONF_UNSET_SIZE);
|
|
1228
|
|
1229 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
|
|
1230 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
|
|
1231 } else {
|
|
1232 conf->upstream.max_temp_file_size =
|
|
1233 conf->upstream.max_temp_file_size_conf;
|
|
1234 }
|
|
1235
|
|
1236 if (conf->upstream.max_temp_file_size != 0
|
|
1237 && conf->upstream.max_temp_file_size < size) {
|
|
1238 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1239 "\"uwsgi_max_temp_file_size\" must be equal to zero to disable "
|
|
1240 "the temporary files usage or must be equal or bigger than "
|
|
1241 "maximum of the value of \"uwsgi_buffer_size\" and "
|
|
1242 "one of the \"uwsgi_buffers\"");
|
|
1243
|
|
1244 return NGX_CONF_ERROR;
|
|
1245 }
|
|
1246
|
|
1247
|
|
1248 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
|
|
1249 prev->upstream.ignore_headers,
|
|
1250 NGX_CONF_BITMASK_SET);
|
|
1251
|
|
1252
|
|
1253 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
|
|
1254 prev->upstream.next_upstream,
|
|
1255 (NGX_CONF_BITMASK_SET
|
|
1256 |NGX_HTTP_UPSTREAM_FT_ERROR
|
|
1257 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
|
|
1258
|
|
1259 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
1260 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
|
|
1261 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
1262 }
|
|
1263
|
|
1264 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
|
|
1265 prev->upstream.temp_path,
|
|
1266 &ngx_http_uwsgi_temp_path)
|
|
1267 != NGX_OK)
|
|
1268 {
|
|
1269 return NGX_CONF_ERROR;
|
|
1270 }
|
|
1271
|
|
1272 #if (NGX_HTTP_CACHE)
|
|
1273
|
|
1274 ngx_conf_merge_ptr_value(conf->upstream.cache,
|
|
1275 prev->upstream.cache, NULL);
|
|
1276
|
|
1277 if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
|
|
1278 ngx_shm_zone_t *shm_zone;
|
|
1279
|
|
1280 shm_zone = conf->upstream.cache;
|
|
1281
|
|
1282 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1283 "\"uwsgi_cache\" zone \"%V\" is unknown",
|
|
1284 &shm_zone->shm.name);
|
|
1285
|
|
1286 return NGX_CONF_ERROR;
|
|
1287 }
|
|
1288
|
|
1289 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
|
|
1290 prev->upstream.cache_min_uses, 1);
|
|
1291
|
|
1292 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
|
|
1293 prev->upstream.cache_use_stale,
|
|
1294 (NGX_CONF_BITMASK_SET
|
|
1295 |NGX_HTTP_UPSTREAM_FT_OFF));
|
|
1296
|
|
1297 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
1298 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
|
|
1299 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
1300 }
|
|
1301
|
644
|
1302 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_ERROR) {
|
|
1303 conf->upstream.cache_use_stale |= NGX_HTTP_UPSTREAM_FT_NOLIVE;
|
|
1304 }
|
|
1305
|
576
|
1306 if (conf->upstream.cache_methods == 0) {
|
|
1307 conf->upstream.cache_methods = prev->upstream.cache_methods;
|
|
1308 }
|
|
1309
|
|
1310 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
|
|
1311
|
588
|
1312 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass,
|
|
1313 prev->upstream.cache_bypass, NULL);
|
|
1314
|
576
|
1315 ngx_conf_merge_ptr_value(conf->upstream.no_cache,
|
|
1316 prev->upstream.no_cache, NULL);
|
|
1317
|
|
1318 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
|
|
1319 prev->upstream.cache_valid, NULL);
|
|
1320
|
|
1321 if (conf->cache_key.value.data == NULL) {
|
|
1322 conf->cache_key = prev->cache_key;
|
|
1323 }
|
|
1324
|
|
1325 #endif
|
|
1326
|
|
1327 ngx_conf_merge_value(conf->upstream.pass_request_headers,
|
|
1328 prev->upstream.pass_request_headers, 1);
|
|
1329 ngx_conf_merge_value(conf->upstream.pass_request_body,
|
|
1330 prev->upstream.pass_request_body, 1);
|
|
1331
|
|
1332 ngx_conf_merge_value(conf->upstream.intercept_errors,
|
|
1333 prev->upstream.intercept_errors, 0);
|
|
1334
|
|
1335 ngx_conf_merge_str_value(conf->uwsgi_string, prev->uwsgi_string, "");
|
|
1336
|
|
1337 hash.max_size = 512;
|
|
1338 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
|
|
1339 hash.name = "uwsgi_hide_headers_hash";
|
|
1340
|
|
1341 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
|
584
|
1342 &prev->upstream, ngx_http_uwsgi_hide_headers, &hash)
|
576
|
1343 != NGX_OK)
|
|
1344 {
|
|
1345 return NGX_CONF_ERROR;
|
|
1346 }
|
|
1347
|
|
1348 if (conf->upstream.upstream == NULL) {
|
|
1349 conf->upstream.upstream = prev->upstream.upstream;
|
|
1350 }
|
|
1351
|
|
1352 if (conf->uwsgi_lengths == NULL) {
|
|
1353 conf->uwsgi_lengths = prev->uwsgi_lengths;
|
|
1354 conf->uwsgi_values = prev->uwsgi_values;
|
|
1355 }
|
|
1356
|
592
|
1357 if (conf->upstream.upstream || conf->uwsgi_lengths) {
|
|
1358 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
|
1359 if (clcf->handler == NULL && clcf->lmt_excpt) {
|
|
1360 clcf->handler = ngx_http_uwsgi_handler;
|
|
1361 }
|
|
1362 }
|
|
1363
|
576
|
1364 ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0);
|
|
1365 ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0);
|
|
1366
|
642
|
1367 if (ngx_http_uwsgi_merge_params(cf, conf, prev) != NGX_OK) {
|
|
1368 return NGX_CONF_ERROR;
|
|
1369 }
|
|
1370
|
|
1371 return NGX_CONF_OK;
|
|
1372 }
|
|
1373
|
576
|
1374
|
642
|
1375 static ngx_int_t
|
|
1376 ngx_http_uwsgi_merge_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
|
|
1377 ngx_http_uwsgi_loc_conf_t *prev)
|
|
1378 {
|
|
1379 u_char *p;
|
|
1380 size_t size;
|
|
1381 uintptr_t *code;
|
|
1382 ngx_uint_t i, nsrc;
|
|
1383 ngx_array_t headers_names;
|
576
|
1384 #if (NGX_HTTP_CACHE)
|
642
|
1385 ngx_array_t params_merged;
|
|
1386 #endif
|
|
1387 ngx_keyval_t *src;
|
|
1388 ngx_hash_key_t *hk;
|
|
1389 ngx_hash_init_t hash;
|
|
1390 ngx_http_script_compile_t sc;
|
|
1391 ngx_http_script_copy_code_t *copy;
|
576
|
1392
|
642
|
1393 if (conf->params_source == NULL) {
|
|
1394 conf->params_source = prev->params_source;
|
576
|
1395
|
642
|
1396 if (prev->headers_hash.buckets
|
|
1397 #if (NGX_HTTP_CACHE)
|
|
1398 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
|
|
1399 #endif
|
|
1400 )
|
|
1401 {
|
|
1402 conf->flushes = prev->flushes;
|
|
1403 conf->params_len = prev->params_len;
|
|
1404 conf->params = prev->params;
|
|
1405 conf->headers_hash = prev->headers_hash;
|
|
1406 conf->header_params = prev->header_params;
|
|
1407
|
|
1408 return NGX_OK;
|
576
|
1409 }
|
642
|
1410 }
|
576
|
1411
|
642
|
1412 if (conf->params_source == NULL
|
|
1413 #if (NGX_HTTP_CACHE)
|
|
1414 && (conf->upstream.cache == NULL)
|
576
|
1415 #endif
|
642
|
1416 )
|
|
1417 {
|
|
1418 conf->headers_hash.buckets = (void *) 1;
|
|
1419 return NGX_OK;
|
576
|
1420 }
|
|
1421
|
|
1422 conf->params_len = ngx_array_create(cf->pool, 64, 1);
|
|
1423 if (conf->params_len == NULL) {
|
642
|
1424 return NGX_ERROR;
|
576
|
1425 }
|
|
1426
|
|
1427 conf->params = ngx_array_create(cf->pool, 512, 1);
|
|
1428 if (conf->params == NULL) {
|
642
|
1429 return NGX_ERROR;
|
576
|
1430 }
|
|
1431
|
|
1432 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
|
|
1433 != NGX_OK)
|
|
1434 {
|
642
|
1435 return NGX_ERROR;
|
576
|
1436 }
|
|
1437
|
642
|
1438 if (conf->params_source) {
|
|
1439 src = conf->params_source->elts;
|
|
1440 nsrc = conf->params_source->nelts;
|
|
1441
|
|
1442 } else {
|
|
1443 src = NULL;
|
|
1444 nsrc = 0;
|
|
1445 }
|
576
|
1446
|
|
1447 #if (NGX_HTTP_CACHE)
|
|
1448
|
|
1449 if (conf->upstream.cache) {
|
|
1450 ngx_keyval_t *h, *s;
|
|
1451
|
642
|
1452 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
|
|
1453 != NGX_OK)
|
|
1454 {
|
|
1455 return NGX_ERROR;
|
|
1456 }
|
|
1457
|
|
1458 for (i = 0; i < nsrc; i++) {
|
576
|
1459
|
642
|
1460 s = ngx_array_push(¶ms_merged);
|
|
1461 if (s == NULL) {
|
|
1462 return NGX_ERROR;
|
|
1463 }
|
|
1464
|
|
1465 *s = src[i];
|
|
1466 }
|
|
1467
|
|
1468 h = ngx_http_uwsgi_cache_headers;
|
|
1469
|
|
1470 while (h->key.len) {
|
|
1471
|
|
1472 src = params_merged.elts;
|
|
1473 nsrc = params_merged.nelts;
|
|
1474
|
|
1475 for (i = 0; i < nsrc; i++) {
|
576
|
1476 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
|
|
1477 goto next;
|
|
1478 }
|
|
1479 }
|
|
1480
|
642
|
1481 s = ngx_array_push(¶ms_merged);
|
576
|
1482 if (s == NULL) {
|
642
|
1483 return NGX_ERROR;
|
576
|
1484 }
|
|
1485
|
|
1486 *s = *h;
|
|
1487
|
|
1488 next:
|
|
1489
|
|
1490 h++;
|
|
1491 }
|
642
|
1492
|
|
1493 src = params_merged.elts;
|
|
1494 nsrc = params_merged.nelts;
|
576
|
1495 }
|
|
1496
|
|
1497 #endif
|
|
1498
|
642
|
1499 for (i = 0; i < nsrc; i++) {
|
576
|
1500
|
|
1501 if (src[i].key.len > sizeof("HTTP_") - 1
|
|
1502 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
|
|
1503 {
|
|
1504 hk = ngx_array_push(&headers_names);
|
|
1505 if (hk == NULL) {
|
642
|
1506 return NGX_ERROR;
|
576
|
1507 }
|
|
1508
|
|
1509 hk->key.len = src[i].key.len - 5;
|
|
1510 hk->key.data = src[i].key.data + 5;
|
|
1511 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len);
|
|
1512 hk->value = (void *) 1;
|
|
1513
|
|
1514 if (src[i].value.len == 0) {
|
|
1515 continue;
|
|
1516 }
|
|
1517 }
|
|
1518
|
|
1519 copy = ngx_array_push_n(conf->params_len,
|
|
1520 sizeof(ngx_http_script_copy_code_t));
|
|
1521 if (copy == NULL) {
|
642
|
1522 return NGX_ERROR;
|
576
|
1523 }
|
|
1524
|
|
1525 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
|
|
1526 copy->len = src[i].key.len;
|
|
1527
|
|
1528
|
|
1529 size = (sizeof(ngx_http_script_copy_code_t)
|
|
1530 + src[i].key.len + sizeof(uintptr_t) - 1)
|
|
1531 & ~(sizeof(uintptr_t) - 1);
|
|
1532
|
|
1533 copy = ngx_array_push_n(conf->params, size);
|
|
1534 if (copy == NULL) {
|
642
|
1535 return NGX_ERROR;
|
576
|
1536 }
|
|
1537
|
|
1538 copy->code = ngx_http_script_copy_code;
|
|
1539 copy->len = src[i].key.len;
|
|
1540
|
|
1541 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
1542 ngx_memcpy(p, src[i].key.data, src[i].key.len);
|
|
1543
|
|
1544
|
|
1545 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1546
|
|
1547 sc.cf = cf;
|
|
1548 sc.source = &src[i].value;
|
|
1549 sc.flushes = &conf->flushes;
|
|
1550 sc.lengths = &conf->params_len;
|
|
1551 sc.values = &conf->params;
|
|
1552
|
|
1553 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
642
|
1554 return NGX_ERROR;
|
576
|
1555 }
|
|
1556
|
|
1557 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
1558 if (code == NULL) {
|
642
|
1559 return NGX_ERROR;
|
576
|
1560 }
|
|
1561
|
|
1562 *code = (uintptr_t) NULL;
|
|
1563
|
|
1564
|
|
1565 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
|
1566 if (code == NULL) {
|
642
|
1567 return NGX_ERROR;
|
576
|
1568 }
|
|
1569
|
|
1570 *code = (uintptr_t) NULL;
|
|
1571 }
|
|
1572
|
|
1573 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
1574 if (code == NULL) {
|
642
|
1575 return NGX_ERROR;
|
576
|
1576 }
|
|
1577
|
|
1578 *code = (uintptr_t) NULL;
|
|
1579
|
|
1580 conf->header_params = headers_names.nelts;
|
|
1581
|
|
1582 hash.hash = &conf->headers_hash;
|
|
1583 hash.key = ngx_hash_key_lc;
|
|
1584 hash.max_size = 512;
|
|
1585 hash.bucket_size = 64;
|
|
1586 hash.name = "uwsgi_params_hash";
|
|
1587 hash.pool = cf->pool;
|
|
1588 hash.temp_pool = NULL;
|
|
1589
|
642
|
1590 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
|
576
|
1591 }
|
|
1592
|
|
1593
|
|
1594 static char *
|
|
1595 ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1596 {
|
|
1597 ngx_http_uwsgi_loc_conf_t *uwcf = conf;
|
|
1598
|
|
1599 ngx_url_t u;
|
|
1600 ngx_str_t *value, *url;
|
|
1601 ngx_uint_t n;
|
|
1602 ngx_http_core_loc_conf_t *clcf;
|
|
1603 ngx_http_script_compile_t sc;
|
|
1604
|
|
1605 if (uwcf->upstream.upstream || uwcf->uwsgi_lengths) {
|
|
1606 return "is duplicate";
|
|
1607 }
|
|
1608
|
|
1609 clcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module);
|
|
1610 clcf->handler = ngx_http_uwsgi_handler;
|
|
1611
|
|
1612 value = cf->args->elts;
|
|
1613
|
|
1614 url = &value[1];
|
|
1615
|
|
1616 n = ngx_http_script_variables_count(url);
|
|
1617
|
|
1618 if (n) {
|
|
1619
|
|
1620 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1621
|
|
1622 sc.cf = cf;
|
|
1623 sc.source = url;
|
|
1624 sc.lengths = &uwcf->uwsgi_lengths;
|
|
1625 sc.values = &uwcf->uwsgi_values;
|
|
1626 sc.variables = n;
|
|
1627 sc.complete_lengths = 1;
|
|
1628 sc.complete_values = 1;
|
|
1629
|
|
1630 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
1631 return NGX_CONF_ERROR;
|
|
1632 }
|
|
1633
|
|
1634 return NGX_CONF_OK;
|
|
1635 }
|
|
1636
|
|
1637 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
1638
|
|
1639 u.url = value[1];
|
|
1640 u.no_resolve = 1;
|
|
1641
|
|
1642 uwcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
|
|
1643 if (uwcf->upstream.upstream == NULL) {
|
|
1644 return NGX_CONF_ERROR;
|
|
1645 }
|
|
1646
|
|
1647 if (clcf->name.data[clcf->name.len - 1] == '/') {
|
|
1648 clcf->auto_redirect = 1;
|
|
1649 }
|
|
1650
|
|
1651 return NGX_CONF_OK;
|
|
1652 }
|
|
1653
|
|
1654
|
|
1655 static char *
|
|
1656 ngx_http_uwsgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1657 {
|
|
1658 ngx_http_uwsgi_loc_conf_t *uwcf = conf;
|
|
1659
|
|
1660 ngx_str_t *value;
|
|
1661 ngx_http_script_compile_t sc;
|
|
1662
|
|
1663 if (uwcf->upstream.store != NGX_CONF_UNSET || uwcf->upstream.store_lengths)
|
|
1664 {
|
|
1665 return "is duplicate";
|
|
1666 }
|
|
1667
|
|
1668 value = cf->args->elts;
|
|
1669
|
|
1670 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
1671 uwcf->upstream.store = 0;
|
|
1672 return NGX_CONF_OK;
|
|
1673 }
|
|
1674
|
|
1675 #if (NGX_HTTP_CACHE)
|
|
1676
|
|
1677 if (uwcf->upstream.cache != NGX_CONF_UNSET_PTR
|
|
1678 && uwcf->upstream.cache != NULL)
|
|
1679 {
|
|
1680 return "is incompatible with \"uwsgi_cache\"";
|
|
1681 }
|
|
1682
|
|
1683 #endif
|
|
1684
|
|
1685 if (ngx_strcmp(value[1].data, "on") == 0) {
|
|
1686 uwcf->upstream.store = 1;
|
|
1687 return NGX_CONF_OK;
|
|
1688 }
|
|
1689
|
|
1690 /* include the terminating '\0' into script */
|
|
1691 value[1].len++;
|
|
1692
|
|
1693 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1694
|
|
1695 sc.cf = cf;
|
|
1696 sc.source = &value[1];
|
|
1697 sc.lengths = &uwcf->upstream.store_lengths;
|
|
1698 sc.values = &uwcf->upstream.store_values;
|
|
1699 sc.variables = ngx_http_script_variables_count(&value[1]);;
|
|
1700 sc.complete_lengths = 1;
|
|
1701 sc.complete_values = 1;
|
|
1702
|
|
1703 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
1704 return NGX_CONF_ERROR;
|
|
1705 }
|
|
1706
|
|
1707 return NGX_CONF_OK;
|
|
1708 }
|
|
1709
|
|
1710
|
|
1711 #if (NGX_HTTP_CACHE)
|
|
1712
|
|
1713 static char *
|
|
1714 ngx_http_uwsgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1715 {
|
|
1716 ngx_http_uwsgi_loc_conf_t *uwcf = conf;
|
|
1717
|
|
1718 ngx_str_t *value;
|
|
1719
|
|
1720 value = cf->args->elts;
|
|
1721
|
|
1722 if (uwcf->upstream.cache != NGX_CONF_UNSET_PTR) {
|
|
1723 return "is duplicate";
|
|
1724 }
|
|
1725
|
|
1726 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
1727 uwcf->upstream.cache = NULL;
|
|
1728 return NGX_CONF_OK;
|
|
1729 }
|
|
1730
|
|
1731 if (uwcf->upstream.store > 0 || uwcf->upstream.store_lengths) {
|
|
1732 return "is incompatible with \"uwsgi_store\"";
|
|
1733 }
|
|
1734
|
|
1735 uwcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
|
|
1736 &ngx_http_uwsgi_module);
|
|
1737 if (uwcf->upstream.cache == NULL) {
|
|
1738 return NGX_CONF_ERROR;
|
|
1739 }
|
|
1740
|
|
1741 return NGX_CONF_OK;
|
|
1742 }
|
|
1743
|
|
1744
|
|
1745 static char *
|
|
1746 ngx_http_uwsgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1747 {
|
|
1748 ngx_http_uwsgi_loc_conf_t *uwcf = conf;
|
|
1749
|
|
1750 ngx_str_t *value;
|
|
1751 ngx_http_compile_complex_value_t ccv;
|
|
1752
|
|
1753 value = cf->args->elts;
|
|
1754
|
|
1755 if (uwcf->cache_key.value.len) {
|
|
1756 return "is duplicate";
|
|
1757 }
|
|
1758
|
|
1759 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
1760
|
|
1761 ccv.cf = cf;
|
|
1762 ccv.value = &value[1];
|
|
1763 ccv.complex_value = &uwcf->cache_key;
|
|
1764
|
|
1765 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
1766 return NGX_CONF_ERROR;
|
|
1767 }
|
|
1768
|
|
1769 return NGX_CONF_OK;
|
|
1770 }
|
|
1771
|
|
1772 #endif
|