comparison src/http/ngx_http_upstream.c @ 2757:9cc973b46af1

get a full response if the response is cacheable or storable even a client has closed connection prematurely
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Apr 2009 11:20:55 +0000
parents 4c658be4ab63
children 4e002555652d
comparison
equal deleted inserted replaced
2756:09cab3f8d92e 2757:9cc973b46af1
351 ngx_del_timer(c->read); 351 ngx_del_timer(c->read);
352 } 352 }
353 353
354 u = r->upstream; 354 u = r->upstream;
355 355
356 if (!r->post_action && !u->conf->ignore_client_abort) { 356 u->store = (u->conf->store || u->conf->store_lengths);
357
358 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
357 r->read_event_handler = ngx_http_upstream_rd_check_broken_connection; 359 r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;
358 r->write_event_handler = ngx_http_upstream_wr_check_broken_connection; 360 r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;
359 } 361 }
360 362
361 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { 363 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
437 439
438 cln->handler = ngx_http_upstream_cleanup; 440 cln->handler = ngx_http_upstream_cleanup;
439 cln->data = r; 441 cln->data = r;
440 u->cleanup = &cln->handler; 442 u->cleanup = &cln->handler;
441 443
442 u->store = (u->conf->store || u->conf->store_lengths);
443
444 if (u->resolved == NULL) { 444 if (u->resolved == NULL) {
445 445
446 uscf = u->conf->upstream; 446 uscf = u->conf->upstream;
447 447
448 } else { 448 } else {
777 777
778 c = r->connection; 778 c = r->connection;
779 u = r->upstream; 779 u = r->upstream;
780 780
781 if (c->error) { 781 if (c->error) {
782 ngx_http_upstream_finalize_request(r, u, 782 if (!u->cacheable) {
783 NGX_HTTP_CLIENT_CLOSED_REQUEST); 783 ngx_http_upstream_finalize_request(r, u,
784 NGX_HTTP_CLIENT_CLOSED_REQUEST);
785 }
784 return; 786 return;
785 } 787 }
786 788
787 if (u->peer.connection == NULL) { 789 if (u->peer.connection == NULL) {
788 return; 790 return;
801 803
802 if (ev->kq_errno) { 804 if (ev->kq_errno) {
803 ev->error = 1; 805 ev->error = 1;
804 } 806 }
805 807
806 if (!u->cacheable && !u->store && u->peer.connection) { 808 if (!u->cacheable && u->peer.connection) {
807 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, 809 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
808 "kevent() reported that client closed prematurely " 810 "kevent() reported that client closed prematurely "
809 "connection, so upstream connection is closed too"); 811 "connection, so upstream connection is closed too");
810 ngx_http_upstream_finalize_request(r, u, 812 ngx_http_upstream_finalize_request(r, u,
811 NGX_HTTP_CLIENT_CLOSED_REQUEST); 813 NGX_HTTP_CLIENT_CLOSED_REQUEST);
867 } 869 }
868 870
869 ev->eof = 1; 871 ev->eof = 1;
870 c->error = 1; 872 c->error = 1;
871 873
872 if (!u->cacheable && !u->store && u->peer.connection) { 874 if (!u->cacheable && u->peer.connection) {
873 ngx_log_error(NGX_LOG_INFO, ev->log, err, 875 ngx_log_error(NGX_LOG_INFO, ev->log, err,
874 "client closed prematurely connection, " 876 "client closed prematurely connection, "
875 "so upstream connection is closed too"); 877 "so upstream connection is closed too");
876 ngx_http_upstream_finalize_request(r, u, 878 ngx_http_upstream_finalize_request(r, u,
877 NGX_HTTP_CLIENT_CLOSED_REQUEST); 879 NGX_HTTP_CLIENT_CLOSED_REQUEST);
2484 2486
2485 if (p->downstream_error) { 2487 if (p->downstream_error) {
2486 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 2488 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2487 "http upstream downstream error"); 2489 "http upstream downstream error");
2488 2490
2489 if (!u->cacheable && u->peer.connection) { 2491 if (!u->cacheable && !u->store && u->peer.connection) {
2490 ngx_http_upstream_finalize_request(r, u, 0); 2492 ngx_http_upstream_finalize_request(r, u, 0);
2491 } 2493 }
2492 } 2494 }
2493 } 2495 }
2494 2496