Mercurial > hg > nginx-quic
comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 153:c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 21 Oct 2003 16:49:56 +0000 |
parents | fb48bf4fea1c |
children | eac26585476e |
comparison
equal
deleted
inserted
replaced
152:fb48bf4fea1c | 153:c71aeb75c071 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 /* STUB */ #include <ngx_event_connect.h> | 5 #include <ngx_event_connect.h> |
6 /* STUB */ #include <ngx_event_proxy.h> | 6 #include <ngx_event_pipe.h> |
7 #include <ngx_http.h> | 7 #include <ngx_http.h> |
8 #include <ngx_http_proxy_handler.h> | 8 #include <ngx_http_proxy_handler.h> |
9 | 9 |
10 | 10 |
11 | 11 |
630 | 630 |
631 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) | 631 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) |
632 { | 632 { |
633 int rc, i; | 633 int rc, i; |
634 ngx_table_elt_t *ch, *ph; | 634 ngx_table_elt_t *ch, *ph; |
635 ngx_event_proxy_t *ep; | 635 ngx_event_pipe_t *ep; |
636 ngx_http_request_t *r; | 636 ngx_http_request_t *r; |
637 | 637 |
638 r = p->request; | 638 r = p->request; |
639 | 639 |
640 r->headers_out.content_length = -1; | 640 r->headers_out.content_length_n = -1; |
641 r->headers_out.content_length = NULL; | |
641 | 642 |
642 /* copy an upstream header to r->headers_out */ | 643 /* copy an upstream header to r->headers_out */ |
643 | 644 |
644 ph = (ngx_table_elt_t *) p->headers_in.headers->elts; | 645 ph = (ngx_table_elt_t *) p->headers_in.headers->elts; |
645 for (i = 0; i < p->headers_in.headers->nelts; i++) { | 646 for (i = 0; i < p->headers_in.headers->nelts; i++) { |
653 || &ph[i] == p->headers_in.accept_ranges) { | 654 || &ph[i] == p->headers_in.accept_ranges) { |
654 continue; | 655 continue; |
655 } | 656 } |
656 } | 657 } |
657 | 658 |
658 if (&ph[i] == p->headers_in.content_length) { | |
659 r->headers_out.content_length = | |
660 ngx_atoi(p->headers_in.content_length->value.data, | |
661 p->headers_in.content_length->value.len); | |
662 continue; | |
663 } | |
664 | |
665 ch = ngx_push_table(r->headers_out.headers); | 659 ch = ngx_push_table(r->headers_out.headers); |
666 if (ch == NULL) { | 660 if (ch == NULL) { |
667 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 661 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
668 return; | 662 return; |
669 } | 663 } |
673 if (&ph[i] == p->headers_in.content_type) { | 667 if (&ph[i] == p->headers_in.content_type) { |
674 r->headers_out.content_type = ch; | 668 r->headers_out.content_type = ch; |
675 r->headers_out.content_type->key.len = 0; | 669 r->headers_out.content_type->key.len = 0; |
676 continue; | 670 continue; |
677 } | 671 } |
672 | |
673 if (&ph[i] == p->headers_in.content_length) { | |
674 r->headers_out.content_length_n = | |
675 ngx_atoi(p->headers_in.content_length->value.data, | |
676 p->headers_in.content_length->value.len); | |
677 r->headers_out.content_length = ch; | |
678 continue; | |
679 } | |
678 } | 680 } |
679 | 681 |
680 /* STUB */ | 682 /* STUB */ |
681 | 683 |
682 if (p->headers_in.server) { | 684 if (p->headers_in.server) { |
698 | 700 |
699 rc = ngx_http_send_header(r); | 701 rc = ngx_http_send_header(r); |
700 | 702 |
701 p->header_sent = 1; | 703 p->header_sent = 1; |
702 | 704 |
703 ep = ngx_pcalloc(r->pool, sizeof(ngx_event_proxy_t)); | 705 ep = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t)); |
704 if (ep == NULL) { | 706 if (ep == NULL) { |
705 ngx_http_proxy_finalize_request(p, 0); | 707 ngx_http_proxy_finalize_request(p, 0); |
706 return; | 708 return; |
707 } | 709 } |
708 | 710 |
709 ep->input_filter = ngx_event_proxy_copy_input_filter; | 711 ep->input_filter = ngx_event_pipe_copy_input_filter; |
710 ep->output_filter = (ngx_event_proxy_output_filter_pt) | 712 ep->output_filter = (ngx_event_pipe_output_filter_pt) |
711 ngx_http_output_filter; | 713 ngx_http_output_filter; |
712 ep->output_ctx = r; | 714 ep->output_ctx = r; |
713 ep->bufs = p->lcf->bufs; | 715 ep->bufs = p->lcf->bufs; |
714 ep->max_busy_len = p->lcf->max_busy_len; | 716 ep->max_busy_len = p->lcf->max_busy_len; |
715 ep->upstream = p->upstream.connection; | 717 ep->upstream = p->upstream.connection; |
741 ep->preread_hunks->next = NULL; | 743 ep->preread_hunks->next = NULL; |
742 | 744 |
743 ep->preread_size = p->header_in->last - p->header_in->pos; | 745 ep->preread_size = p->header_in->last - p->header_in->pos; |
744 | 746 |
745 /* | 747 /* |
746 * event_proxy would do p->header_in->last += ep->preread_size | 748 * event_pipe would do p->header_in->last += ep->preread_size |
747 * as these bytes were read. | 749 * as though these bytes were read. |
748 */ | 750 */ |
749 p->header_in->last = p->header_in->pos; | 751 p->header_in->last = p->header_in->pos; |
750 | 752 |
751 /* STUB */ ep->cachable = 0; | 753 /* STUB */ ep->cachable = 1; |
752 | 754 #if 0 |
753 p->event_proxy = ep; | 755 ep->max_temp_file_size = 1000000000; |
756 #endif | |
757 | |
758 p->event_pipe = ep; | |
754 | 759 |
755 #if 0 | 760 #if 0 |
756 lcx = p->log->data; | 761 lcx = p->log->data; |
757 lcx->action = "reading an upstream"; | 762 lcx->action = "reading an upstream"; |
758 #endif | 763 #endif |
769 static void ngx_http_proxy_process_body(ngx_event_t *ev) | 774 static void ngx_http_proxy_process_body(ngx_event_t *ev) |
770 { | 775 { |
771 ngx_connection_t *c; | 776 ngx_connection_t *c; |
772 ngx_http_request_t *r; | 777 ngx_http_request_t *r; |
773 ngx_http_proxy_ctx_t *p; | 778 ngx_http_proxy_ctx_t *p; |
774 ngx_event_proxy_t *ep; | 779 ngx_event_pipe_t *ep; |
775 | 780 |
776 c = ev->data; | 781 c = ev->data; |
777 | 782 |
778 if (ev->write) { | 783 if (ev->write) { |
779 ngx_log_debug(ev->log, "http proxy process downstream"); | 784 ngx_log_debug(ev->log, "http proxy process downstream"); |
784 ngx_log_debug(ev->log, "http proxy process upstream"); | 789 ngx_log_debug(ev->log, "http proxy process upstream"); |
785 p = c->data; | 790 p = c->data; |
786 r = p->request; | 791 r = p->request; |
787 } | 792 } |
788 | 793 |
789 ep = p->event_proxy; | 794 ep = p->event_pipe; |
790 | 795 |
791 if (ev->timedout) { | 796 if (ev->timedout) { |
792 if (ev->write) { | 797 if (ev->write) { |
793 ep->downstream_error = 1; | 798 ep->downstream_error = 1; |
794 | 799 |
795 } else { | 800 } else { |
796 ep->upstream_error = 1; | 801 ep->upstream_error = 1; |
797 } | 802 } |
798 | 803 |
799 } else { | 804 } else { |
800 if (ngx_event_proxy(ep, ev->write) == NGX_ABORT) { | 805 if (ngx_event_pipe(ep, ev->write) == NGX_ABORT) { |
801 ngx_http_proxy_finalize_request(p, 0); | 806 ngx_http_proxy_finalize_request(p, 0); |
802 return; | 807 return; |
803 } | 808 } |
804 } | 809 } |
805 | 810 |
1157 conf->header_size = 4096; | 1162 conf->header_size = 4096; |
1158 conf->read_timeout = 30000; | 1163 conf->read_timeout = 30000; |
1159 | 1164 |
1160 conf->bufs.num = 10; | 1165 conf->bufs.num = 10; |
1161 conf->bufs.size = 4096; | 1166 conf->bufs.size = 4096; |
1162 conf->max_busy_len = 8192 + 4096; | 1167 conf->max_busy_len = 8192; |
1163 | 1168 |
1164 | 1169 |
1165 /* CHECK in _init conf->max_temp_size >= conf->bufs.size !!! */ | 1170 /* CHECK in _init conf->max_temp_size >= conf->bufs.size !!! */ |
1166 conf->max_temp_file_size = 4096 * 6; | 1171 conf->max_temp_file_size = 4096 * 6; |
1167 | 1172 |
1168 | 1173 |
1169 conf->temp_file_write_size = 4096 * 2; | 1174 conf->temp_file_write_size = 4096 * 1; |
1170 | 1175 |
1171 ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), | 1176 ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), |
1172 NULL); | 1177 NULL); |
1173 | 1178 |
1174 conf->temp_path->name.data = "temp"; | 1179 conf->temp_path->name.data = "temp"; |