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