comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 10:46833bd150cb NGINX_0_1_5

nginx 0.1.5 *) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned not enough data" alerts. *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors on Solaris in proxy mode without sendfile. On other platforms that do not support sendfile at all the process got caught in an endless loop. *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. *) Bugfix: segmentation fault on Solaris. *) Bugfix: on-line upgrade did not work on Linux. *) Bugfix: the ngx_http_autoindex_module module did not escape the spaces, the quotes, and the percent signs in the directory listing. *) Change: the decrease of the copy operations. *) Feature: the userid_p3p directive.
author Igor Sysoev <http://sysoev.ru>
date Thu, 11 Nov 2004 00:00:00 +0300
parents 80ba094c6b3e
children 6f8b0dc0f8dd
comparison
equal deleted inserted replaced
9:77eee314ddbd 10:46833bd150cb
23 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev); 23 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev);
24 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); 24 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
25 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); 25 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *);
26 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p); 26 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p);
27 static void ngx_http_proxy_process_body(ngx_event_t *ev); 27 static void ngx_http_proxy_process_body(ngx_event_t *ev);
28 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type); 28 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p,
29 ngx_uint_t ft_type);
29 30
30 31
31 static ngx_str_t http_methods[] = { 32 static ngx_str_t http_methods[] = {
32 ngx_string("GET "), 33 ngx_string("GET "),
33 ngx_string("HEAD "), 34 ngx_string("HEAD "),
135 len = r->method_name.len; 136 len = r->method_name.len;
136 } 137 }
137 138
138 if (r->quoted_uri) { 139 if (r->quoted_uri) {
139 escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, 140 escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
140 r->uri.len - uc->location->len); 141 r->uri.len - uc->location->len,
142 NGX_ESCAPE_URI);
141 } else { 143 } else {
142 escape = 0; 144 escape = 0;
143 } 145 }
144 146
145 len += uc->uri.len 147 len += uc->uri.len
244 246
245 b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len); 247 b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len);
246 248
247 if (escape) { 249 if (escape) {
248 ngx_escape_uri(b->last, r->uri.data + uc->location->len, 250 ngx_escape_uri(b->last, r->uri.data + uc->location->len,
249 r->uri.len - uc->location->len); 251 r->uri.len - uc->location->len, NGX_ESCAPE_URI);
250 b->last += r->uri.len - uc->location->len + escape; 252 b->last += r->uri.len - uc->location->len + escape;
251 253
252 } else { 254 } else {
253 b->last = ngx_cpymem(b->last, 255 b->last = ngx_cpymem(b->last,
254 r->uri.data + uc->location->len, 256 r->uri.data + uc->location->len,
407 header[i].value.len); 409 header[i].value.len);
408 410
409 *(b->last++) = CR; *(b->last++) = LF; 411 *(b->last++) = CR; *(b->last++) = LF;
410 412
411 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 413 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
412 "http proxy header: \"%s: %s\"", 414 "http proxy header: \"%V: %V\"",
413 header[i].key.data, header[i].value.data); 415 &header[i].key, &header[i].value);
414 } 416 }
415 417
416 /* add "\r\n" at the header end */ 418 /* add "\r\n" at the header end */
417 *(b->last++) = CR; *(b->last++) = LF; 419 *(b->last++) = CR; *(b->last++) = LF;
418 420
668 #endif 670 #endif
669 671
670 672
671 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) 673 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
672 { 674 {
673 int rc; 675 ngx_int_t rc;
674 ngx_connection_t *c; 676 ngx_connection_t *c;
675 ngx_http_request_t *r; 677 ngx_http_request_t *r;
676 ngx_output_chain_ctx_t *output; 678 ngx_output_chain_ctx_t *output;
677 ngx_chain_writer_ctx_t *writer; 679 ngx_chain_writer_ctx_t *writer;
678 680
681 p->request->connection->single_connection = 0; 683 p->request->connection->single_connection = 0;
682 684
683 rc = ngx_event_connect_peer(&p->upstream->peer); 685 rc = ngx_event_connect_peer(&p->upstream->peer);
684 686
685 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, 687 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
686 "http proxy connect: %d", rc); 688 "http proxy connect: %i", rc);
687 689
688 if (rc == NGX_ERROR) { 690 if (rc == NGX_ERROR) {
689 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 691 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
690 return; 692 return;
691 } 693 }
702 c = p->upstream->peer.connection; 704 c = p->upstream->peer.connection;
703 705
704 c->data = p; 706 c->data = p;
705 c->write->event_handler = ngx_http_proxy_send_request_handler; 707 c->write->event_handler = ngx_http_proxy_send_request_handler;
706 c->read->event_handler = ngx_http_proxy_process_upstream_status_line; 708 c->read->event_handler = ngx_http_proxy_process_upstream_status_line;
709
710 c->sendfile = r->connection->sendfile;
707 711
708 c->pool = r->pool; 712 c->pool = r->pool;
709 c->read->log = c->write->log = c->log = r->connection->log; 713 c->read->log = c->write->log = c->log = r->connection->log;
710 714
711 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ 715 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */
1026 } 1030 }
1027 ngx_cpystrn(p->upstream->status_line.data, p->status_start, 1031 ngx_cpystrn(p->upstream->status_line.data, p->status_start,
1028 p->upstream->status_line.len + 1); 1032 p->upstream->status_line.len + 1);
1029 1033
1030 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0, 1034 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
1031 "http proxy status %d \"%s\"", 1035 "http proxy status %ui \"%V\"",
1032 p->upstream->status, p->upstream->status_line.data); 1036 p->upstream->status, &p->upstream->status_line);
1033 1037
1034 1038
1035 /* init or reinit the p->upstream->headers_in.headers table */ 1039 /* init or reinit the p->upstream->headers_in.headers table */
1036 1040
1037 if (p->upstream->headers_in.headers.part.elts) { 1041 if (p->upstream->headers_in.headers.part.elts) {
1141 break; 1145 break;
1142 } 1146 }
1143 } 1147 }
1144 1148
1145 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 1149 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1146 "http proxy header: \"%s: %s\"", 1150 "http proxy header: \"%V: %V\"", &h->key, &h->value);
1147 h->key.data, h->value.data);
1148 1151
1149 continue; 1152 continue;
1150 1153
1151 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { 1154 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
1152 1155
1465 1468
1466 #endif 1469 #endif
1467 1470
1468 if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) { 1471 if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
1469 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, 1472 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
1470 "http proxy upstream exit: " PTR_FMT, ep->out); 1473 "http proxy upstream exit: %p", ep->out);
1471 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); 1474 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
1472 ngx_http_proxy_finalize_request(p, 0); 1475 ngx_http_proxy_finalize_request(p, 0);
1473 return; 1476 return;
1474 } 1477 }
1475 } 1478 }
1482 } 1485 }
1483 } 1486 }
1484 } 1487 }
1485 1488
1486 1489
1487 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type) 1490 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p,
1491 ngx_uint_t ft_type)
1488 { 1492 {
1489 int status; 1493 ngx_uint_t status;
1490 1494
1491 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, 1495 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
1492 "http proxy next upstream: %d", ft_type); 1496 "http proxy next upstream: %ui", ft_type);
1493 1497
1494 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); 1498 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
1495 1499
1496 if (ft_type != NGX_HTTP_PROXY_FT_HTTP_404) { 1500 if (ft_type != NGX_HTTP_PROXY_FT_HTTP_404) {
1497 ngx_event_connect_peer_failed(&p->upstream->peer); 1501 ngx_event_connect_peer_failed(&p->upstream->peer);