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