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