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