comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 28:7ca9bdc82b3f NGINX_0_1_14

nginx 0.1.14 *) Feature: the autoconfiguration directives: --http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and --http-fastcgi-temp-path=PATH *) Change: the directory name for the temporary files with the client request body is specified by directive client_body_temp_path, by default it is <prefix>/client_body_temp. *) Feature: the ngx_http_fastcgi_module and the directives: fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params, fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout, fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers, fastcgi_busy_buffers_size, fastcgi_temp_path, fastcgi_max_temp_file_size, fastcgi_temp_file_write_size, fastcgi_next_upstream, and fastcgi_x_powered_by. *) Bugfix: the "[alert] zero size buf" error; bug appeared in 0.1.3. *) Change: the URI must be specified after the host name in the proxy_pass directive. *) Change: the %3F symbol in the URI was considered as the argument string start. *) Feature: the unix domain sockets support in the ngx_http_proxy_module. *) Feature: the ssl_engine and ssl_ciphers directives. Thanks to Sergey Skvortsov for SSL-accelerator.
author Igor Sysoev <http://sysoev.ru>
date Tue, 18 Jan 2005 00:00:00 +0300
parents 8b6db3bda591
children aab2ea7c0458
comparison
equal deleted inserted replaced
27:66901c2556fd 28:7ca9bdc82b3f
12 #include <ngx_http.h> 12 #include <ngx_http.h>
13 #include <ngx_http_proxy_handler.h> 13 #include <ngx_http_proxy_handler.h>
14 14
15 15
16 static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p); 16 static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p);
17 static void ngx_http_proxy_init_upstream(void *data); 17 static void ngx_http_proxy_init_upstream(ngx_http_request_t *r);
18 static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p); 18 static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p);
19 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p); 19 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p);
20 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p); 20 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p);
21 static void ngx_http_proxy_send_request_handler(ngx_event_t *wev); 21 static void ngx_http_proxy_send_request_handler(ngx_event_t *wev);
22 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev); 22 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev);
51 51
52 52
53 int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p) 53 int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
54 { 54 {
55 int rc; 55 int rc;
56 ngx_temp_file_t *tf;
57 ngx_http_request_t *r; 56 ngx_http_request_t *r;
58 ngx_http_request_body_t *rb;
59 ngx_http_proxy_upstream_t *u; 57 ngx_http_proxy_upstream_t *u;
60 58
61 r = p->request; 59 r = p->request;
62 60
63 if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t)))) { 61 if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t)))) {
73 u->peer.lock = &r->connection->lock; 71 u->peer.lock = &r->connection->lock;
74 #endif 72 #endif
75 73
76 u->method = r->method; 74 u->method = r->method;
77 75
78 if (!(rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)))) { 76 rc = ngx_http_read_client_request_body(r, ngx_http_proxy_init_upstream);
79 return NGX_HTTP_INTERNAL_SERVER_ERROR;
80 }
81 r->request_body = rb;
82
83 if (r->headers_in.content_length_n <= 0) {
84 ngx_http_proxy_init_upstream(p);
85 return NGX_DONE;
86 }
87
88 if (!(tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
89 return NGX_HTTP_INTERNAL_SERVER_ERROR;
90 }
91
92 tf->file.fd = NGX_INVALID_FILE;
93 tf->file.log = r->connection->log;
94 tf->path = p->lcf->temp_path;
95 tf->pool = r->pool;
96 tf->warn = "a client request body is buffered to a temporary file";
97 /* tf->persistent = 0; */
98
99 rb->handler = ngx_http_proxy_init_upstream;
100 rb->data = p;
101 /* rb->bufs = NULL; */
102 /* rb->buf = NULL; */
103 /* rb->rest = 0; */
104
105 rb->temp_file = tf;
106
107 rc = ngx_http_read_client_request_body(r);
108 77
109 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { 78 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
110 return rc; 79 return rc;
111 } 80 }
112 81
426 395
427 return chain; 396 return chain;
428 } 397 }
429 398
430 399
431 static void ngx_http_proxy_init_upstream(void *data) 400 static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
432 { 401 {
433 ngx_http_proxy_ctx_t *p = data;
434 402
435 ngx_chain_t *cl; 403 ngx_chain_t *cl;
436 ngx_http_request_t *r; 404 ngx_http_proxy_ctx_t *p;
437 ngx_output_chain_ctx_t *output; 405 ngx_output_chain_ctx_t *output;
438 ngx_chain_writer_ctx_t *writer; 406 ngx_chain_writer_ctx_t *writer;
439 ngx_http_proxy_log_ctx_t *ctx; 407 ngx_http_proxy_log_ctx_t *ctx;
440 408
441 r = p->request; 409 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
442 410
443 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 411 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
444 "http proxy init upstream, client timer: %d", 412 "http proxy init upstream, client timer: %d",
445 r->connection->read->timer_set); 413 r->connection->read->timer_set);
446 414
500 468
501 output->sendfile = r->connection->sendfile; 469 output->sendfile = r->connection->sendfile;
502 output->pool = r->pool; 470 output->pool = r->pool;
503 output->bufs.num = 1; 471 output->bufs.num = 1;
504 output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; 472 output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
505 output->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer; 473 output->output_filter = ngx_chain_writer;
506 474
507 if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) { 475 if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
508 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 476 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
509 return; 477 return;
510 } 478 }
698 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 666 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
699 return; 667 return;
700 } 668 }
701 669
702 p->state->peer = 670 p->state->peer =
703 &p->upstream->peer.peers->peers[p->upstream->peer.cur_peer].addr_port_text; 671 &p->upstream->peer.peers->peer[p->upstream->peer.cur_peer].name;
704 672
705 if (rc == NGX_CONNECT_ERROR) { 673 if (rc == NGX_CONNECT_ERROR) {
706 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_ERROR); 674 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_ERROR);
707 return; 675 return;
708 } 676 }
731 if (p->request_sent) { 699 if (p->request_sent) {
732 ngx_http_proxy_reinit_upstream(p); 700 ngx_http_proxy_reinit_upstream(p);
733 } 701 }
734 702
735 if (r->request_body->buf) { 703 if (r->request_body->buf) {
736 if (r->request_body->temp_file->file.fd != NGX_INVALID_FILE) { 704 if (r->request_body->temp_file) {
737 705
738 if (!(output->free = ngx_alloc_chain_link(r->pool))) { 706 if (!(output->free = ngx_alloc_chain_link(r->pool))) {
739 ngx_http_proxy_finalize_request(p, 707 ngx_http_proxy_finalize_request(p,
740 NGX_HTTP_INTERNAL_SERVER_ERROR); 708 NGX_HTTP_INTERNAL_SERVER_ERROR);
741 return; 709 return;
1345 ngx_http_proxy_finalize_request(p, 0); 1313 ngx_http_proxy_finalize_request(p, 0);
1346 return; 1314 return;
1347 } 1315 }
1348 ep->preread_bufs->buf = p->header_in; 1316 ep->preread_bufs->buf = p->header_in;
1349 ep->preread_bufs->next = NULL; 1317 ep->preread_bufs->next = NULL;
1318 p->header_in->recycled = 1;
1350 1319
1351 ep->preread_size = p->header_in->last - p->header_in->pos; 1320 ep->preread_size = p->header_in->last - p->header_in->pos;
1352 1321
1353 if (p->cachable) { 1322 if (p->cachable) {
1354 ep->buf_to_file = ngx_calloc_buf(r->pool); 1323 ep->buf_to_file = ngx_calloc_buf(r->pool);