comparison src/http/modules/ngx_http_uwsgi_module.c @ 3543:e132566a942e

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