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