comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 189:c966c09be66b

nginx-0.0.1-2003-11-18-19:49:00 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 18 Nov 2003 16:49:00 +0000
parents 0061d1f0908d
children 02a715e85df1
comparison
equal deleted inserted replaced
188:0061d1f0908d 189:c966c09be66b
17 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev); 17 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev);
18 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev); 18 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev);
19 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); 19 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
20 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); 20 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *);
21 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p); 21 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p);
22 static void ngx_http_proxy_check_broken_connection(ngx_event_t *wev);
23 static void ngx_http_proxy_process_body(ngx_event_t *ev); 22 static void ngx_http_proxy_process_body(ngx_event_t *ev);
24 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type); 23 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type);
25 24
26 25
27 static ngx_str_t http_methods[] = { 26 static ngx_str_t http_methods[] = {
500 } 499 }
501 500
502 if (rc == NGX_AGAIN) { 501 if (rc == NGX_AGAIN) {
503 ngx_add_timer(c->write, p->lcf->send_timeout); 502 ngx_add_timer(c->write, p->lcf->send_timeout);
504 503
505 if (ngx_handle_write_event(c->write, /* STUB: lowat */ 0) == NGX_ERROR) 504 c->write->available = /* STUB: lowat */ 0;
506 { 505 if (ngx_handle_write_event(c->write, NGX_LOWAT_EVENT) == NGX_ERROR) {
507 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 506 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
508 return; 507 return;
509 } 508 }
510 509
511 return; 510 return;
524 523
525 c->tcp_nopush = 0; 524 c->tcp_nopush = 0;
526 return; 525 return;
527 } 526 }
528 527
528 ngx_add_timer(c->read, p->lcf->read_timeout);
529
529 #if 0 530 #if 0
530 if (c->read->ready) { 531 if (c->read->ready) {
531 532
532 /* post aio operation */ 533 /* post aio operation */
533 534
564 p->action = "sending request to upstream"; 565 p->action = "sending request to upstream";
565 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT); 566 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT);
566 return; 567 return;
567 } 568 }
568 569
569 if (p->request->connection->write->eof) { 570 if (p->request->connection->write->eof
570 ngx_http_proxy_close_connection(p); 571 && (!p->cachable || !p->request_sent))
571 ngx_http_close_connection(p->request->connection); 572 {
573 ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
574 return;
572 } 575 }
573 576
574 ngx_http_proxy_send_request(p); 577 ngx_http_proxy_send_request(p);
575 } 578 }
576 579
866 869
867 n = ngx_recv(p->upstream->peer.connection, p->header_in->last, 870 n = ngx_recv(p->upstream->peer.connection, p->header_in->last,
868 p->header_in->end - p->header_in->last); 871 p->header_in->end - p->header_in->last);
869 872
870 if (n == NGX_AGAIN) { 873 if (n == NGX_AGAIN) {
874 #if 0
871 ngx_add_timer(rev, p->lcf->read_timeout); 875 ngx_add_timer(rev, p->lcf->read_timeout);
876 #endif
872 877
873 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { 878 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
874 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 879 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
875 return NGX_ERROR; 880 return NGX_ERROR;
876 } 881 }
1040 1045
1041 return; 1046 return;
1042 } 1047 }
1043 1048
1044 1049
1045 static void ngx_http_proxy_check_broken_connection(ngx_event_t *wev)
1046 {
1047 ngx_connection_t *c;
1048 ngx_http_request_t *r;
1049 ngx_http_proxy_ctx_t *p;
1050
1051 ngx_log_debug(wev->log, "http proxy check client");
1052
1053 c = wev->data;
1054 r = c->data;
1055 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1056
1057 #if (HAVE_KQUEUE)
1058 if (wev->kq_eof) {
1059 wev->eof = 1;
1060
1061 if (wev->kq_errno) {
1062 wev->error = 1;
1063 }
1064
1065 if (!p->cachable && p->upstream->peer.connection) {
1066 ngx_log_error(NGX_LOG_INFO, wev->log, wev->kq_errno,
1067 "client closed prematurely connection, "
1068 "so upstream connection is closed too");
1069 ngx_http_proxy_close_connection(p);
1070
1071 } else {
1072 ngx_log_error(NGX_LOG_INFO, wev->log, wev->kq_errno,
1073 "client closed prematurely connection");
1074 }
1075
1076 if (p->upstream->peer.connection == NULL) {
1077 ngx_http_close_connection(c);
1078 }
1079 }
1080 #endif
1081 }
1082
1083
1084 static void ngx_http_proxy_process_body(ngx_event_t *ev) 1050 static void ngx_http_proxy_process_body(ngx_event_t *ev)
1085 { 1051 {
1086 ngx_connection_t *c; 1052 ngx_connection_t *c;
1087 ngx_http_request_t *r; 1053 ngx_http_request_t *r;
1088 ngx_http_proxy_ctx_t *p; 1054 ngx_http_proxy_ctx_t *p;
1213 1179
1214 if (p->upstream->peer.connection) { 1180 if (p->upstream->peer.connection) {
1215 ngx_http_proxy_close_connection(p); 1181 ngx_http_proxy_close_connection(p);
1216 } 1182 }
1217 1183
1184 if (p->request->connection->write->eof) {
1185 ngx_http_proxy_finalize_request(p, status ? status:
1186 NGX_HTTP_CLIENT_CLOSED_REQUEST);
1187 }
1188
1218 if (status) { 1189 if (status) {
1219 p->state->status = status; 1190 p->state->status = status;
1220 1191
1221 if (p->upstream->peer.tries == 0 || !(p->lcf->next_upstream & ft_type)) 1192 if (p->upstream->peer.tries == 0 || !(p->lcf->next_upstream & ft_type))
1222 { 1193 {