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