comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 172:caa57ddf6d77

nginx-0.0.1-2003-11-04-01:20:44 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 03 Nov 2003 22:20:44 +0000
parents aff0e5d32af8
children ea464a6c0581
comparison
equal deleted inserted replaced
171:aff0e5d32af8 172:caa57ddf6d77
36 { ngx_string("busy_lock"), NGX_HTTP_PROXY_FT_BUSY_LOCK }, 36 { ngx_string("busy_lock"), NGX_HTTP_PROXY_FT_BUSY_LOCK },
37 { ngx_string("max_waiting"), NGX_HTTP_PROXY_FT_MAX_WAITING }, 37 { ngx_string("max_waiting"), NGX_HTTP_PROXY_FT_MAX_WAITING },
38 { ngx_null_string, 0 } 38 { ngx_null_string, 0 }
39 }; 39 };
40 40
41
42 static ngx_conf_num_bounds_t ngx_http_proxy_lm_factor_bounds = {
43 ngx_conf_check_num_bounds, 0, 100
44 };
45
46
41 static ngx_command_t ngx_http_proxy_commands[] = { 47 static ngx_command_t ngx_http_proxy_commands[] = {
42 48
43 { ngx_string("proxy_pass"), 49 { ngx_string("proxy_pass"),
44 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 50 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
45 ngx_http_proxy_set_pass, 51 ngx_http_proxy_set_pass,
122 ngx_conf_set_flag_slot, 128 ngx_conf_set_flag_slot,
123 NGX_HTTP_LOC_CONF_OFFSET, 129 NGX_HTTP_LOC_CONF_OFFSET,
124 offsetof(ngx_http_proxy_loc_conf_t, cache), 130 offsetof(ngx_http_proxy_loc_conf_t, cache),
125 NULL }, 131 NULL },
126 132
133
127 { ngx_string("proxy_pass_server"), 134 { ngx_string("proxy_pass_server"),
128 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 135 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
129 ngx_conf_set_flag_slot, 136 ngx_conf_set_flag_slot,
130 NGX_HTTP_LOC_CONF_OFFSET, 137 NGX_HTTP_LOC_CONF_OFFSET,
131 offsetof(ngx_http_proxy_loc_conf_t, pass_server), 138 offsetof(ngx_http_proxy_loc_conf_t, pass_server),
132 NULL }, 139 NULL },
140
141 { ngx_string("proxy_pass_x_accel_expires"),
142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
143 ngx_conf_set_flag_slot,
144 NGX_HTTP_LOC_CONF_OFFSET,
145 offsetof(ngx_http_proxy_loc_conf_t, pass_x_accel_expires),
146 NULL },
147
148 { ngx_string("proxy_ignore_expires"),
149 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
150 ngx_conf_set_flag_slot,
151 NGX_HTTP_LOC_CONF_OFFSET,
152 offsetof(ngx_http_proxy_loc_conf_t, ignore_expires),
153 NULL },
154
155 { ngx_string("proxy_lm_factor"),
156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
157 ngx_conf_set_num_slot,
158 NGX_HTTP_LOC_CONF_OFFSET,
159 offsetof(ngx_http_proxy_loc_conf_t, lm_factor),
160 &ngx_http_proxy_lm_factor_bounds },
161
162 { ngx_string("proxy_default_expires"),
163 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
164 ngx_conf_set_sec_slot,
165 NGX_HTTP_LOC_CONF_OFFSET,
166 offsetof(ngx_http_proxy_loc_conf_t, default_expires),
167 NULL },
168
133 169
134 { ngx_string("proxy_next_upstream"), 170 { ngx_string("proxy_next_upstream"),
135 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY, 171 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY,
136 ngx_conf_set_bitmask_slot, 172 ngx_conf_set_bitmask_slot,
137 NGX_HTTP_LOC_CONF_OFFSET, 173 NGX_HTTP_LOC_CONF_OFFSET,
197 233
198 234
199 static int ngx_http_proxy_handler(ngx_http_request_t *r) 235 static int ngx_http_proxy_handler(ngx_http_request_t *r)
200 { 236 {
201 int rc; 237 int rc;
202 char *last;
203 ngx_http_cache_ctx_t *cctx;
204 ngx_http_proxy_ctx_t *p; 238 ngx_http_proxy_ctx_t *p;
205 239
206 ngx_http_create_ctx(r, p, ngx_http_proxy_module, 240 ngx_http_create_ctx(r, p, ngx_http_proxy_module,
207 sizeof(ngx_http_proxy_ctx_t), 241 sizeof(ngx_http_proxy_ctx_t),
208 NGX_HTTP_INTERNAL_SERVER_ERROR); 242 NGX_HTTP_INTERNAL_SERVER_ERROR);
211 p->request = r; 245 p->request = r;
212 246
213 /* TODO: we currently support reverse proxy only */ 247 /* TODO: we currently support reverse proxy only */
214 p->accel = 1; 248 p->accel = 1;
215 249
216 if (!p->lcf->cache || r->bypass_cache) { 250 ngx_init_array(p->states, r->pool, p->lcf->peers->number,
251 sizeof(ngx_http_proxy_state_t),
252 NGX_HTTP_INTERNAL_SERVER_ERROR);
253
254 if (!(p->state = ngx_push_array(&p->states))) {
255 return NGX_HTTP_INTERNAL_SERVER_ERROR;
256 }
257
258
259 if (!p->lcf->cache) {
260 p->state->cache = NGX_HTTP_PROXY_CACHE_PASS;
261
262 } else if (r->bypass_cache) {
263 p->state->cache = NGX_HTTP_PROXY_CACHE_BYPASS;
264
265 } else if (r->headers_in.authorization) {
266 p->state->cache = NGX_HTTP_PROXY_CACHE_AUTH;
267
268 } else if (r->no_cache) {
269 p->state->cache = NGX_HTTP_PROXY_CACHE_PGNC;
270 p->cachable = 1;
271
272 } else {
273 p->cachable = 1;
274 }
275
276
277 if (p->state->cache) {
217 return ngx_http_proxy_request_upstream(p); 278 return ngx_http_proxy_request_upstream(p);
218 } 279 }
219 280
220 rc = ngx_http_proxy_get_cached_response(p); 281 rc = ngx_http_proxy_get_cached_response(p);
221 282
225 286
226 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { 287 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
227 return rc; 288 return rc;
228 } 289 }
229 290
230 if (rc == NGX_DECLINED || rc == NGX_STALE) { 291 /* rc == NGX_DECLINED || NGX_HTTP_CACHE_STALE || NGX_HTTP_CACHE_AGED */
231 return ngx_http_proxy_request_upstream(p); 292
232 } 293 return ngx_http_proxy_request_upstream(p);
233
234 return NGX_DONE;
235 }
236
237
238 int ngx_http_proxy_log_state(ngx_http_proxy_ctx_t *p, int status)
239 {
240 ngx_http_proxy_state_t *state;
241
242 if (!(state = ngx_push_array(&p->states))) {
243 return NGX_ERROR;
244 }
245
246 state->status = status;
247 state->peer =
248 &p->upstream->peer.peers->peers[p->upstream->peer.cur_peer].addr_port_text;
249
250 return NGX_OK;
251 } 294 }
252 295
253 296
254 void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc) 297 void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc)
255 { 298 {
384 conf->cyclic_temp_file = 0; 427 conf->cyclic_temp_file = 0;
385 428
386 conf->cache = NGX_CONF_UNSET; 429 conf->cache = NGX_CONF_UNSET;
387 430
388 conf->pass_server = NGX_CONF_UNSET; 431 conf->pass_server = NGX_CONF_UNSET;
432 conf->pass_x_accel_expires = NGX_CONF_UNSET;
433 conf->ignore_expires = NGX_CONF_UNSET;
434 conf->lm_factor = NGX_CONF_UNSET;
435 conf->default_expires = NGX_CONF_UNSET;
389 436
390 return conf; 437 return conf;
391 } 438 }
392 439
393 440
434 "temp", 1, 2, 0, cf->pool); 481 "temp", 1, 2, 0, cf->pool);
435 482
436 ngx_conf_merge_value(conf->cache, prev->cache, 0); 483 ngx_conf_merge_value(conf->cache, prev->cache, 0);
437 484
438 ngx_conf_merge_value(conf->pass_server, prev->pass_server, 0); 485 ngx_conf_merge_value(conf->pass_server, prev->pass_server, 0);
486 ngx_conf_merge_value(conf->pass_x_accel_expires,
487 prev->pass_x_accel_expires, 0);
488 ngx_conf_merge_value(conf->ignore_expires, prev->ignore_expires, 0);
489 ngx_conf_merge_value(conf->lm_factor, prev->lm_factor, 0);
490 ngx_conf_merge_sec_value(conf->default_expires, prev->default_expires, 0);
439 491
440 return NULL; 492 return NULL;
441 } 493 }
442 494
443 495