Mercurial > hg > nginx-ranges
comparison src/http/ngx_http_upstream.c @ 32:da8c190bdaba NGINX_0_1_16
nginx 0.1.16
*) Bugfix: if the response were transferred by chunks, then on the HEAD
request the final chunk was issued.
*) Bugfix: the "Connection: keep-alive" header were issued, even if the
keepalive_timeout directive forbade the keep-alive use.
*) Bugfix: the errors in the ngx_http_fastcgi_module caused the
segmentation faults.
*) Bugfix: the compressed response encrypted by SSL may not transferred
complete.
*) Bugfix: the TCP-specific TCP_NODELAY, TCP_NOPSUH, and TCP_CORK
options, are not used for the unix domain sockets.
*) Feature: the rewrite directive supports the arguments rewriting.
*) Bugfix: the response code 400 was returned for the POST request with
the "Content-Length: 0" header; bug appeared in 0.1.14.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 25 Jan 2005 00:00:00 +0300 |
parents | e1ada20fc595 |
children | aab2ea7c0458 |
comparison
equal
deleted
inserted
replaced
31:1b17dd824438 | 32:da8c190bdaba |
---|---|
115 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 115 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 u->peer.log = r->connection->log; | 119 u->peer.log = r->connection->log; |
120 u->saved_ctx = r->connection->log->data; | 120 u->saved_log_ctx = r->connection->log->data; |
121 u->saved_handler = r->connection->log->handler; | 121 u->saved_log_handler = r->connection->log->handler; |
122 r->connection->log->data = u->log_ctx; | 122 r->connection->log->data = u->log_ctx; |
123 r->connection->log->handler = u->log_handler; | 123 r->connection->log->handler = u->log_handler; |
124 | 124 |
125 u->output.sendfile = r->connection->sendfile; | 125 u->output.sendfile = r->connection->sendfile; |
126 u->output.pool = r->pool; | 126 u->output.pool = r->pool; |
158 ngx_http_upstream_t *u; | 158 ngx_http_upstream_t *u; |
159 | 159 |
160 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, | 160 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
161 "http upstream check client, write event:%d", ev->write); | 161 "http upstream check client, write event:%d", ev->write); |
162 | 162 |
163 c = ev->data; | |
164 r = c->data; | |
165 u = r->upstream; | |
166 | |
167 if (u->peer.connection == NULL) { | |
168 return; | |
169 } | |
170 | |
163 #if (NGX_HAVE_KQUEUE) | 171 #if (NGX_HAVE_KQUEUE) |
164 | 172 |
165 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 173 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
166 | 174 |
167 if (!ev->pending_eof) { | 175 if (!ev->pending_eof) { |
171 ev->eof = 1; | 179 ev->eof = 1; |
172 | 180 |
173 if (ev->kq_errno) { | 181 if (ev->kq_errno) { |
174 ev->error = 1; | 182 ev->error = 1; |
175 } | 183 } |
176 | |
177 c = ev->data; | |
178 r = c->data; | |
179 u = r->upstream; | |
180 | 184 |
181 if (!u->cachable && u->peer.connection) { | 185 if (!u->cachable && u->peer.connection) { |
182 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | 186 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
183 "kevent() reported that client closed " | 187 "kevent() reported that client closed " |
184 "prematurely connection, " | 188 "prematurely connection, " |
201 return; | 205 return; |
202 } | 206 } |
203 | 207 |
204 #endif | 208 #endif |
205 | 209 |
206 c = ev->data; | |
207 | |
208 n = recv(c->fd, buf, 1, MSG_PEEK); | 210 n = recv(c->fd, buf, 1, MSG_PEEK); |
209 | 211 |
210 err = ngx_socket_errno; | 212 err = ngx_socket_errno; |
211 | 213 |
212 /* | 214 /* |
216 | 218 |
217 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { | 219 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
218 return; | 220 return; |
219 } | 221 } |
220 | 222 |
221 r = c->data; | |
222 u = r->upstream; | |
223 | |
224 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) { | 223 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) { |
225 if (ngx_del_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) { | 224 if (ngx_del_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) { |
226 ngx_http_upstream_finalize_request(r, u, | 225 ngx_http_upstream_finalize_request(r, u, |
227 NGX_HTTP_INTERNAL_SERVER_ERROR); | 226 NGX_HTTP_INTERNAL_SERVER_ERROR); |
228 return; | 227 return; |
240 return; | 239 return; |
241 } | 240 } |
242 | 241 |
243 ev->error = 1; | 242 ev->error = 1; |
244 | 243 |
245 } else { | 244 } else { /* n == 0 */ |
246 /* n == 0 */ | |
247 err = 0; | 245 err = 0; |
248 } | 246 } |
249 | 247 |
250 if (!u->cachable && u->peer.connection) { | 248 if (!u->cachable && u->peer.connection) { |
251 ngx_log_error(NGX_LOG_INFO, ev->log, err, | 249 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
270 static void ngx_http_upstream_connect(ngx_http_request_t *r, | 268 static void ngx_http_upstream_connect(ngx_http_request_t *r, |
271 ngx_http_upstream_t *u) | 269 ngx_http_upstream_t *u) |
272 { | 270 { |
273 ngx_int_t rc; | 271 ngx_int_t rc; |
274 ngx_connection_t *c; | 272 ngx_connection_t *c; |
275 ngx_http_log_ctx_t *ctx; | 273 |
276 | 274 r->connection->log->action = "connecting to upstream"; |
277 ctx = r->connection->log->data; | |
278 ctx->action = "connecting to upstream"; | |
279 | 275 |
280 r->connection->single_connection = 0; | 276 r->connection->single_connection = 0; |
281 | 277 |
282 rc = ngx_event_connect_peer(&u->peer); | 278 rc = ngx_event_connect_peer(&u->peer); |
283 | 279 |
411 | 407 |
412 | 408 |
413 static void ngx_http_upstream_send_request(ngx_http_request_t *r, | 409 static void ngx_http_upstream_send_request(ngx_http_request_t *r, |
414 ngx_http_upstream_t *u) | 410 ngx_http_upstream_t *u) |
415 { | 411 { |
416 int rc; | 412 int rc; |
417 ngx_connection_t *c; | 413 ngx_connection_t *c; |
418 ngx_http_log_ctx_t *ctx; | |
419 | 414 |
420 c = u->peer.connection; | 415 c = u->peer.connection; |
421 | 416 |
422 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | 417 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
423 "http upstream send request"); | 418 "http upstream send request"); |
435 return; | 430 return; |
436 } | 431 } |
437 | 432 |
438 #endif | 433 #endif |
439 | 434 |
440 ctx = c->log->data; | 435 c->log->action = "sending request to upstream"; |
441 ctx->action = "sending request to upstream"; | |
442 | 436 |
443 rc = ngx_output_chain(&u->output, | 437 rc = ngx_output_chain(&u->output, |
444 u->request_sent ? NULL : r->request_body->bufs); | 438 u->request_sent ? NULL : r->request_body->bufs); |
445 | 439 |
446 u->request_sent = 1; | 440 u->request_sent = 1; |
513 | 507 |
514 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev) | 508 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev) |
515 { | 509 { |
516 ngx_connection_t *c; | 510 ngx_connection_t *c; |
517 ngx_http_request_t *r; | 511 ngx_http_request_t *r; |
518 ngx_http_log_ctx_t *ctx; | |
519 ngx_http_upstream_t *u; | 512 ngx_http_upstream_t *u; |
520 | 513 |
521 c = wev->data; | 514 c = wev->data; |
522 r = c->data; | 515 r = c->data; |
523 u = r->upstream; | 516 u = r->upstream; |
524 | 517 |
525 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, | 518 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, |
526 "http upstream send request handler"); | 519 "http upstream send request handler"); |
527 | 520 |
528 if (wev->timedout) { | 521 if (wev->timedout) { |
529 ctx = c->log->data; | 522 c->log->action = "sending request to upstream"; |
530 ctx->action = "sending request to upstream"; | |
531 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); | 523 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
532 return; | 524 return; |
533 } | 525 } |
534 | 526 |
535 if (r->connection->write->eof && (!u->cachable || !u->request_sent)) { | 527 if (r->connection->write->eof && (!u->cachable || !u->request_sent)) { |
546 { | 538 { |
547 ssize_t n; | 539 ssize_t n; |
548 ngx_int_t rc; | 540 ngx_int_t rc; |
549 ngx_connection_t *c; | 541 ngx_connection_t *c; |
550 ngx_http_request_t *r; | 542 ngx_http_request_t *r; |
551 ngx_http_log_ctx_t *ctx; | |
552 ngx_http_upstream_t *u; | 543 ngx_http_upstream_t *u; |
553 | 544 |
554 c = rev->data; | 545 c = rev->data; |
555 r = c->data; | 546 r = c->data; |
556 u = r->upstream; | 547 u = r->upstream; |
557 | 548 |
558 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, | 549 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, |
559 "http upstream process handler"); | 550 "http upstream process header"); |
560 | 551 |
561 ctx = c->log->data; | 552 c->log->action = "reading response header from upstream"; |
562 ctx->action = "reading response header from upstream"; | |
563 | 553 |
564 if (rev->timedout) { | 554 if (rev->timedout) { |
565 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); | 555 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
566 return; | 556 return; |
567 } | 557 } |
574 return; | 564 return; |
575 } | 565 } |
576 | 566 |
577 u->header_in.pos = u->header_in.start; | 567 u->header_in.pos = u->header_in.start; |
578 u->header_in.last = u->header_in.start; | 568 u->header_in.last = u->header_in.start; |
579 u->header_in.end = u->header_in.last + u->conf->header_buffer_size; | 569 u->header_in.end = u->header_in.start + u->conf->header_buffer_size; |
580 u->header_in.temporary = 1; | 570 u->header_in.temporary = 1; |
581 | 571 |
582 u->header_in.tag = u->output.tag; | 572 u->header_in.tag = u->output.tag; |
583 | 573 |
584 #if 0 | 574 #if 0 |
813 | 803 |
814 static void ngx_http_upstream_process_body(ngx_event_t *ev) | 804 static void ngx_http_upstream_process_body(ngx_event_t *ev) |
815 { | 805 { |
816 ngx_connection_t *c; | 806 ngx_connection_t *c; |
817 ngx_http_request_t *r; | 807 ngx_http_request_t *r; |
818 ngx_http_log_ctx_t *ctx; | |
819 ngx_http_upstream_t *u; | 808 ngx_http_upstream_t *u; |
820 ngx_event_pipe_t *p; | 809 ngx_event_pipe_t *p; |
821 | 810 |
822 c = ev->data; | 811 c = ev->data; |
823 r = c->data; | 812 r = c->data; |
824 u = r->upstream; | 813 u = r->upstream; |
825 | 814 |
826 ctx = ev->log->data; | |
827 | |
828 if (ev->write) { | 815 if (ev->write) { |
829 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, | 816 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
830 "http proxy process downstream"); | 817 "http upstream process downstream"); |
831 ctx->action = "sending to client"; | 818 c->log->action = "sending to client"; |
832 | 819 |
833 } else { | 820 } else { |
834 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, | 821 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
835 "http proxy process upstream"); | 822 "http upstream process upstream"); |
836 ctx->action = "reading upstream body"; | 823 c->log->action = "reading upstream"; |
837 } | 824 } |
838 | 825 |
839 p = &u->pipe; | 826 p = &u->pipe; |
840 | 827 |
841 if (ev->timedout) { | 828 if (ev->timedout) { |
880 } | 867 } |
881 | 868 |
882 #endif | 869 #endif |
883 | 870 |
884 if (p->upstream_done || p->upstream_eof || p->upstream_error) { | 871 if (p->upstream_done || p->upstream_eof || p->upstream_error) { |
885 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, | 872 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
886 "http proxy upstream exit: %p", p->out); | 873 "http upstream exit: %p", p->out); |
887 #if 0 | 874 #if 0 |
888 ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock); | 875 ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock); |
889 #endif | 876 #endif |
890 ngx_http_upstream_finalize_request(r, u, 0); | 877 ngx_http_upstream_finalize_request(r, u, 0); |
891 return; | 878 return; |
892 } | 879 } |
893 } | 880 } |
894 | 881 |
895 if (p->downstream_error) { | 882 if (p->downstream_error) { |
896 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, | 883 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
897 "http proxy downstream error"); | 884 "http upstream downstream error"); |
898 | 885 |
899 if (!u->cachable && u->peer.connection) { | 886 if (!u->cachable && u->peer.connection) { |
900 ngx_http_upstream_finalize_request(r, u, 0); | 887 ngx_http_upstream_finalize_request(r, u, 0); |
901 } | 888 } |
902 } | 889 } |
974 | 961 |
975 #if (NGX_HTTP_CACHE) | 962 #if (NGX_HTTP_CACHE) |
976 | 963 |
977 if (u->stale && (u->conf->use_stale & ft_type)) { | 964 if (u->stale && (u->conf->use_stale & ft_type)) { |
978 ngx_http_upstream_finalize_request(r, u, | 965 ngx_http_upstream_finalize_request(r, u, |
979 ngx_http_proxy_send_cached_response(r)); | 966 ngx_http_send_cached_response(r)); |
980 return; | 967 return; |
981 } | 968 } |
982 | 969 |
983 #endif | 970 #endif |
984 | 971 |
1008 | 995 |
1009 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, | 996 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
1010 ngx_http_upstream_t *u, | 997 ngx_http_upstream_t *u, |
1011 ngx_int_t rc) | 998 ngx_int_t rc) |
1012 { | 999 { |
1013 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1000 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1014 "finalize http upstream request"); | 1001 "finalize http upstream request: %i", rc); |
1015 | 1002 |
1016 u->finalize_request(r, rc); | 1003 u->finalize_request(r, rc); |
1017 | 1004 |
1018 if (u->peer.connection) { | 1005 if (u->peer.connection) { |
1019 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1006 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1021 u->peer.connection->fd); | 1008 u->peer.connection->fd); |
1022 | 1009 |
1023 ngx_close_connection(u->peer.connection); | 1010 ngx_close_connection(u->peer.connection); |
1024 } | 1011 } |
1025 | 1012 |
1013 u->peer.connection = NULL; | |
1014 | |
1026 if (u->header_sent | 1015 if (u->header_sent |
1027 && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) | 1016 && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) |
1028 { | 1017 { |
1029 rc = 0; | 1018 rc = 0; |
1030 } | 1019 } |
1031 | 1020 |
1032 if (u->saved_ctx) { | 1021 if (u->saved_log_ctx) { |
1033 r->connection->log->data = u->saved_ctx; | 1022 r->connection->log->data = u->saved_log_ctx; |
1034 r->connection->log->handler = u->saved_handler; | 1023 r->connection->log->handler = u->saved_log_handler; |
1035 } | 1024 } |
1036 | 1025 |
1037 if (u->pipe.temp_file) { | 1026 if (u->pipe.temp_file) { |
1038 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1027 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1039 "http upstream temp fd: %d", | 1028 "http upstream temp fd: %d", |
1041 } | 1030 } |
1042 | 1031 |
1043 #if 0 | 1032 #if 0 |
1044 if (u->cache) { | 1033 if (u->cache) { |
1045 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1034 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1046 "http proxy cache fd: %d", | 1035 "http upstream cache fd: %d", |
1047 u->cache->ctx.file.fd); | 1036 u->cache->ctx.file.fd); |
1048 } | 1037 } |
1049 #endif | 1038 #endif |
1050 | 1039 |
1051 if (u->pipe.temp_file) { | 1040 if (u->pipe.temp_file) { |
1055 } else if (u->cache) { | 1044 } else if (u->cache) { |
1056 r->file.fd = u->cache->ctx.file.fd; | 1045 r->file.fd = u->cache->ctx.file.fd; |
1057 #endif | 1046 #endif |
1058 } | 1047 } |
1059 | 1048 |
1049 r->connection->log->action = "sending to client"; | |
1050 | |
1060 if (rc == 0 && r->main == NULL) { | 1051 if (rc == 0 && r->main == NULL) { |
1061 rc = ngx_http_send_last(r); | 1052 rc = ngx_http_send_last(r); |
1062 } | 1053 } |
1063 | 1054 |
1064 ngx_http_finalize_request(r, rc); | 1055 ngx_http_finalize_request(r, rc); |
1109 *buf++ = ' '; | 1100 *buf++ = ' '; |
1110 } | 1101 } |
1111 } | 1102 } |
1112 | 1103 |
1113 | 1104 |
1114 u_char *ngx_http_upstream_log_error(void *data, u_char *buf, size_t len) | 1105 u_char *ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len) |
1115 { | 1106 { |
1116 ngx_http_log_ctx_t *ctx = data; | |
1117 | |
1118 u_char *p; | 1107 u_char *p; |
1119 ngx_int_t escape; | 1108 ngx_int_t escape; |
1120 ngx_str_t uri; | 1109 ngx_str_t uri; |
1110 ngx_http_log_ctx_t *ctx; | |
1121 ngx_http_request_t *r; | 1111 ngx_http_request_t *r; |
1122 ngx_http_upstream_t *u; | 1112 ngx_http_upstream_t *u; |
1123 ngx_peer_connection_t *peer; | 1113 ngx_peer_connection_t *peer; |
1124 | 1114 |
1115 ctx = log->data; | |
1125 r = ctx->request; | 1116 r = ctx->request; |
1126 u = r->upstream; | 1117 u = r->upstream; |
1127 peer = &u->peer; | 1118 peer = &u->peer; |
1128 | 1119 |
1129 p = ngx_snprintf(buf, len, | 1120 p = ngx_snprintf(buf, len, |
1130 " while %s, client: %V, URL: %V, upstream: %V%V%s%V", | 1121 " while %s, client: %V, URL: %V, upstream: %V%V%s%V", |
1131 ctx->action, | 1122 log->action, |
1132 &r->connection->addr_text, | 1123 &r->connection->addr_text, |
1133 &r->unparsed_uri, | 1124 &r->unparsed_uri, |
1134 &u->schema, | 1125 &u->schema, |
1135 &peer->peers->peer[peer->cur_peer].name, | 1126 &peer->peers->peer[peer->cur_peer].name, |
1136 peer->peers->peer[peer->cur_peer].uri_separator, | 1127 peer->peers->peer[peer->cur_peer].uri_separator, |