comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 151:2d9e4a8b6d11

nginx-0.0.1-2003-10-20-21:14:07 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 20 Oct 2003 17:14:07 +0000
parents ad5f382c9e7d
children fb48bf4fea1c
comparison
equal deleted inserted replaced
150:ad5f382c9e7d 151:2d9e4a8b6d11
15 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p); 15 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p);
16 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev); 16 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev);
17 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); 17 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
18 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); 18 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *);
19 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p); 19 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p);
20 static void ngx_http_proxy_process_upstream(ngx_event_t *rev); 20 static void ngx_http_proxy_process_body(ngx_event_t *ev);
21 static void ngx_http_proxy_process_downstream(ngx_event_t *wev);
22 21
23 static int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p); 22 static int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p);
24 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p); 23 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p);
25 static void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc); 24 static void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc);
26 static void ngx_http_proxy_close_connection(ngx_connection_t *c); 25 static void ngx_http_proxy_close_connection(ngx_connection_t *c);
233 232
234 if (&header[i] == r->headers_in.connection) { 233 if (&header[i] == r->headers_in.connection) {
235 continue; 234 continue;
236 } 235 }
237 236
238 /* TODO: delete "Keep-Alive" header */ 237 if (&header[i] == r->headers_in.keep_alive) {
238 continue;
239 }
239 240
240 h->last = ngx_cpymem(h->last, header[i].key.data, header[i].key.len); 241 h->last = ngx_cpymem(h->last, header[i].key.data, header[i].key.len);
241 242
242 *(h->last++) = ':'; *(h->last++) = ' '; 243 *(h->last++) = ':'; *(h->last++) = ' ';
243 244
739 ep->preread_hunks->hunk = p->header_in; 740 ep->preread_hunks->hunk = p->header_in;
740 ep->preread_hunks->next = NULL; 741 ep->preread_hunks->next = NULL;
741 742
742 ep->preread_size = p->header_in->last - p->header_in->pos; 743 ep->preread_size = p->header_in->last - p->header_in->pos;
743 744
745 /* STUB */ ep->cachable = 0;
746
744 p->event_proxy = ep; 747 p->event_proxy = ep;
745 748
746 #if 0 749 #if 0
747 lcx = p->log->data; 750 lcx = p->log->data;
748 lcx->action = "reading an upstream"; 751 lcx->action = "reading an upstream";
749 #endif 752 #endif
750 753
751 p->upstream.connection->read->event_handler = 754 p->upstream.connection->read->event_handler = ngx_http_proxy_process_body;
752 ngx_http_proxy_process_upstream; 755 r->connection->write->event_handler = ngx_http_proxy_process_body;
753 r->connection->write->event_handler = 756
754 ngx_http_proxy_process_downstream; 757 ngx_http_proxy_process_body(p->upstream.connection->read);
755
756 ngx_http_proxy_process_upstream(p->upstream.connection->read);
757 758
758 return; 759 return;
759 } 760 }
760 761
761 762
762 static void ngx_http_proxy_process_upstream(ngx_event_t *rev) 763 static void ngx_http_proxy_process_body(ngx_event_t *ev)
763 {
764 ngx_connection_t *c;
765 ngx_http_proxy_ctx_t *p;
766
767 c = rev->data;
768 p = c->data;
769
770 ngx_log_debug(rev->log, "http proxy process upstream");
771
772 if (rev->timedout) {
773 ngx_http_proxy_close_connection(c);
774 p->upstream.connection = NULL;
775 return;
776 }
777
778 if (ngx_event_proxy(p->event_proxy, 0) == NGX_ABORT) {
779 ngx_http_proxy_finalize_request(p, 0);
780 return;
781 }
782
783 if (p->event_proxy->upstream_eof
784 || p->event_proxy->upstream_error
785 || p->event_proxy->upstream_done)
786 {
787 ngx_http_proxy_close_connection(c);
788 p->upstream.connection = NULL;
789 return;
790 }
791
792 return;
793 }
794
795
796 static void ngx_http_proxy_process_downstream(ngx_event_t *wev)
797 { 764 {
798 ngx_connection_t *c; 765 ngx_connection_t *c;
799 ngx_http_request_t *r; 766 ngx_http_request_t *r;
800 ngx_http_proxy_ctx_t *p; 767 ngx_http_proxy_ctx_t *p;
801 768 ngx_event_proxy_t *ep;
802 c = wev->data; 769
803 r = c->data; 770 c = ev->data;
804 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module); 771
772 if (ev->write) {
773 ngx_log_debug(ev->log, "http proxy process downstream");
774 r = c->data;
775 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
776
777 } else {
778 ngx_log_debug(ev->log, "http proxy process upstream");
779 p = c->data;
780 r = p->request;
781 }
782
783 ep = p->event_proxy;
784
785 if (ev->timedout) {
786 if (ev->write) {
787 ep->downstream_error = 1;
788
789 } else {
790 ep->upstream_error = 1;
791 }
792
793 } else {
794 if (ngx_event_proxy(ep, ev->write) == NGX_ABORT) {
795 ngx_http_proxy_finalize_request(p, 0);
796 return;
797 }
798 }
799
800 if (p->upstream.connection) {
801 if (ep->upstream_done) {
802 /* TODO: update cache */
803
804 } else if (ep->upstream_eof) {
805 /* TODO: check length & update cache */
806 }
807
808 if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
809 ngx_http_proxy_close_connection(c);
810 p->upstream.connection = NULL;
811 }
812 }
813
814 if (ep->downstream_done) {
815 ngx_log_debug(ev->log, "http proxy downstream done");
816 ngx_http_proxy_finalize_request(p, r->main ? 0 : ngx_http_send_last(r));
817 return;
818 }
819
820 if (ep->downstream_error) {
821 if (!p->cachable && p->upstream.connection) {
822 ngx_http_proxy_close_connection(c);
823 p->upstream.connection = NULL;
824 }
805 825
806 ngx_log_debug(wev->log, "http proxy process downstream"); 826 if (p->upstream.connection == NULL) {
807 827 ngx_http_close_connection(c);
808 if (wev->timedout) { 828 }
809 ngx_http_close_connection(c);
810 return;
811 }
812
813 if (ngx_event_proxy(p->event_proxy, 1) == NGX_ABORT) {
814 ngx_http_proxy_finalize_request(p, 0);
815 return;
816 }
817
818 if (p->event_proxy->downstream_done) {
819 ngx_log_debug(wev->log, "http proxy downstream done");
820 ngx_http_proxy_finalize_request(p, r->main ? 0:
821 ngx_http_send_last(p->request));
822 return;
823 }
824
825 if (p->event_proxy->downstream_error) {
826 ngx_http_close_connection(c);
827 return;
828 } 829 }
829 830
830 return; 831 return;
831 } 832 }
832 833
1149 conf->read_timeout = 30000; 1150 conf->read_timeout = 30000;
1150 1151
1151 conf->bufs.num = 10; 1152 conf->bufs.num = 10;
1152 conf->bufs.size = 4096; 1153 conf->bufs.size = 4096;
1153 conf->max_busy_len = 8192 + 4096; 1154 conf->max_busy_len = 8192 + 4096;
1154 conf->max_temp_file_size = 4096 * 5; 1155 conf->max_temp_file_size = 4096 * 6;
1155 conf->temp_file_write_size = 4096 * 2; 1156 conf->temp_file_write_size = 4096 * 2;
1156 1157
1157 ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), 1158 ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)),
1158 NULL); 1159 NULL);
1159 1160