Mercurial > hg > nginx
comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 175:e92c2c647c57
nginx-0.0.1-2003-11-05-20:03:41 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 05 Nov 2003 17:03:41 +0000 |
parents | ea464a6c0581 |
children | c0552e5ab567 |
comparison
equal
deleted
inserted
replaced
174:ea464a6c0581 | 175:e92c2c647c57 |
---|---|
264 } | 264 } |
265 | 265 |
266 ngx_memzero(p->state, sizeof(ngx_http_proxy_state_t)); | 266 ngx_memzero(p->state, sizeof(ngx_http_proxy_state_t)); |
267 | 267 |
268 | 268 |
269 if (!p->lcf->cache) { | 269 if (!p->lcf->cache |
270 || (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD)) | |
271 { | |
270 p->state->cache = NGX_HTTP_PROXY_CACHE_PASS; | 272 p->state->cache = NGX_HTTP_PROXY_CACHE_PASS; |
271 | 273 |
272 } else if (r->bypass_cache) { | 274 } else if (r->bypass_cache) { |
273 p->state->cache = NGX_HTTP_PROXY_CACHE_BYPASS; | 275 p->state->cache = NGX_HTTP_PROXY_CACHE_BYPASS; |
274 | 276 |
288 return ngx_http_proxy_request_upstream(p); | 290 return ngx_http_proxy_request_upstream(p); |
289 } | 291 } |
290 | 292 |
291 rc = ngx_http_proxy_get_cached_response(p); | 293 rc = ngx_http_proxy_get_cached_response(p); |
292 | 294 |
295 if (rc == NGX_DONE || rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { | |
296 return rc; | |
297 } | |
298 | |
293 p->valid_header_in = 1; | 299 p->valid_header_in = 1; |
294 | 300 |
295 if (rc == NGX_OK) { | 301 if (rc == NGX_OK) { |
296 return ngx_http_proxy_send_cached_response(p); | 302 return ngx_http_proxy_send_cached_response(p); |
297 } | |
298 | |
299 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { | |
300 return rc; | |
301 } | 303 } |
302 | 304 |
303 /* rc == NGX_DECLINED || NGX_HTTP_CACHE_STALE || NGX_HTTP_CACHE_AGED */ | 305 /* rc == NGX_DECLINED || NGX_HTTP_CACHE_STALE || NGX_HTTP_CACHE_AGED */ |
304 | 306 |
305 return ngx_http_proxy_request_upstream(p); | 307 return ngx_http_proxy_request_upstream(p); |
310 { | 312 { |
311 ngx_log_debug(p->request->connection->log, | 313 ngx_log_debug(p->request->connection->log, |
312 "finalize http proxy request"); | 314 "finalize http proxy request"); |
313 | 315 |
314 if (p->upstream->peer.connection) { | 316 if (p->upstream->peer.connection) { |
315 ngx_http_proxy_close_connection(p->upstream->peer.connection); | 317 ngx_http_proxy_close_connection(p); |
316 p->upstream->peer.connection = NULL; | |
317 } | 318 } |
318 | 319 |
319 if (p->header_sent | 320 if (p->header_sent |
320 && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) | 321 && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) |
321 { | 322 { |
327 | 328 |
328 ngx_http_finalize_request(p->request, rc); | 329 ngx_http_finalize_request(p->request, rc); |
329 } | 330 } |
330 | 331 |
331 | 332 |
332 void ngx_http_proxy_close_connection(ngx_connection_t *c) | 333 void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) |
333 { | 334 { |
335 ngx_connection_t *c; | |
336 | |
337 c = p->upstream->peer.connection; | |
338 p->upstream->peer.connection = NULL; | |
339 | |
340 if (p->lcf->busy_lock) { | |
341 p->lcf->busy_lock->conn_n--; | |
342 } | |
343 | |
334 ngx_log_debug(c->log, "proxy close connection: %d" _ c->fd); | 344 ngx_log_debug(c->log, "proxy close connection: %d" _ c->fd); |
335 | 345 |
336 if (c->fd == -1) { | 346 if (c->fd == -1) { |
337 #if 0 | 347 #if 0 |
338 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed"); | 348 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed"); |
503 conf->busy_lock = prev->busy_lock; | 513 conf->busy_lock = prev->busy_lock; |
504 } | 514 } |
505 | 515 |
506 if (conf->busy_lock && conf->cache && conf->busy_lock->busy == NULL) { | 516 if (conf->busy_lock && conf->cache && conf->busy_lock->busy == NULL) { |
507 | 517 |
518 /* ngx_alloc_shared() */ | |
519 conf->busy_lock->busy_mask = | |
520 ngx_palloc(cf->pool, (conf->busy_lock->max_conn + 7) / 8); | |
521 if (conf->busy_lock->busy_mask == NULL) { | |
522 return NGX_CONF_ERROR; | |
523 } | |
524 | |
508 /* 16 bytes are 128 bits of the md5 */ | 525 /* 16 bytes are 128 bits of the md5 */ |
509 | 526 |
510 /* ngx_alloc_shared() */ | 527 /* ngx_alloc_shared() */ |
511 conf->busy_lock->busy = ngx_palloc(cf->pool, | 528 conf->busy_lock->busy = ngx_palloc(cf->pool, |
512 16 * conf->busy_lock->max_conn); | 529 16 * conf->busy_lock->max_conn); |