Mercurial > hg > nginx
comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 164:84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 29 Oct 2003 08:30:44 +0000 |
parents | fb61ba77beba |
children | 894a01c6aea3 |
comparison
equal
deleted
inserted
replaced
163:fb61ba77beba | 164:84036764e215 |
---|---|
473 | 473 |
474 } else { | 474 } else { |
475 | 475 |
476 /* rc == NGX_OK */ | 476 /* rc == NGX_OK */ |
477 | 477 |
478 if (c->read->ready) { | |
479 /* post aio operation */ | |
480 ngx_http_proxy_process_upstream_status_line(c->read); | |
481 } | |
482 | |
478 if (ngx_handle_level_write_event(c->write) == NGX_ERROR) { | 483 if (ngx_handle_level_write_event(c->write) == NGX_ERROR) { |
479 ngx_http_proxy_finalize_request(p, | 484 ngx_http_proxy_finalize_request(p, |
480 NGX_HTTP_INTERNAL_SERVER_ERROR); | 485 NGX_HTTP_INTERNAL_SERVER_ERROR); |
481 return; | 486 return; |
482 } | 487 } |
740 ((char *) &p->headers_in + headers_in[i].offset)) = h; | 745 ((char *) &p->headers_in + headers_in[i].offset)) = h; |
741 break; | 746 break; |
742 } | 747 } |
743 } | 748 } |
744 | 749 |
745 ngx_log_debug(c->log, "HTTP proxy header: '%s: %s'" _ | 750 ngx_log_debug(c->log, "HTTP proxy header: %08X '%s: %s'" _ |
746 h->key.data _ h->value.data); | 751 h _ h->key.data _ h->value.data); |
747 | 752 |
748 continue; | 753 continue; |
749 | 754 |
750 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | 755 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { |
751 | 756 |
789 rev = p->upstream.connection->read; | 794 rev = p->upstream.connection->read; |
790 | 795 |
791 n = p->header_in->last - p->header_in->pos; | 796 n = p->header_in->last - p->header_in->pos; |
792 | 797 |
793 if (n > 0) { | 798 if (n > 0) { |
794 #if 0 | |
795 /* TODO THINK */ | |
796 rev->ready = 0; | |
797 #endif | |
798 return n; | 799 return n; |
799 } | 800 } |
800 | 801 |
801 n = ngx_recv(p->upstream.connection, p->header_in->last, | 802 n = ngx_recv(p->upstream.connection, p->header_in->last, |
802 p->header_in->end - p->header_in->last); | 803 p->header_in->end - p->header_in->last); |
803 | 804 |
804 if (n == NGX_AGAIN) { | 805 if (n == NGX_AGAIN) { |
805 ngx_add_timer(rev, p->lcf->read_timeout); | 806 ngx_add_timer(rev, p->lcf->read_timeout); |
806 | 807 |
807 if (ngx_handle_read_event(rev) == NGX_ERROR) { | 808 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
808 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 809 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
809 return NGX_ERROR; | 810 return NGX_ERROR; |
810 } | 811 } |
811 | 812 |
812 return NGX_AGAIN; | 813 return NGX_AGAIN; |
827 } | 828 } |
828 | 829 |
829 | 830 |
830 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) | 831 static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) |
831 { | 832 { |
832 int rc, i; | 833 int rc, i; |
833 ngx_table_elt_t *ch, *ph; | 834 ngx_table_elt_t *ch, *h; |
834 ngx_event_pipe_t *ep; | 835 ngx_event_pipe_t *ep; |
835 ngx_http_request_t *r; | 836 ngx_http_request_t *r; |
837 ngx_http_core_loc_conf_t *clcf; | |
836 | 838 |
837 r = p->request; | 839 r = p->request; |
838 | 840 |
839 r->headers_out.status = p->status; | 841 r->headers_out.status = p->status; |
840 | 842 |
841 r->headers_out.content_length_n = -1; | 843 r->headers_out.content_length_n = -1; |
842 r->headers_out.content_length = NULL; | 844 r->headers_out.content_length = NULL; |
843 | 845 |
844 /* copy an upstream header to r->headers_out */ | 846 /* copy an upstream header to r->headers_out */ |
845 | 847 |
846 ph = (ngx_table_elt_t *) p->headers_in.headers->elts; | 848 h = p->headers_in.headers->elts; |
847 for (i = 0; i < p->headers_in.headers->nelts; i++) { | 849 for (i = 0; i < p->headers_in.headers->nelts; i++) { |
848 | 850 |
849 if (&ph[i] == p->headers_in.connection) { | 851 if (&h[i] == p->headers_in.connection) { |
850 continue; | 852 continue; |
851 } | 853 } |
852 | 854 |
853 if (p->accel) { | 855 if (p->accel) { |
854 if (&ph[i] == p->headers_in.date | 856 if (&h[i] == p->headers_in.date |
855 || &ph[i] == p->headers_in.accept_ranges) { | 857 || &h[i] == p->headers_in.accept_ranges) { |
856 continue; | 858 continue; |
857 } | 859 } |
858 | 860 |
859 if (&ph[i] == p->headers_in.server && !p->lcf->pass_server) { | 861 if (&h[i] == p->headers_in.server && !p->lcf->pass_server) { |
860 continue; | 862 continue; |
861 } | 863 } |
862 } | 864 } |
863 | 865 |
864 if (&ph[i] == p->headers_in.content_type) { | 866 if (&h[i] == p->headers_in.content_type) { |
865 r->headers_out.content_type = &ph[i]; | 867 r->headers_out.content_type = &h[i]; |
866 r->headers_out.content_type->key.len = 0; | 868 r->headers_out.content_type->key.len = 0; |
867 continue; | 869 continue; |
868 } | 870 } |
869 | 871 |
870 ch = ngx_push_table(r->headers_out.headers); | 872 ch = ngx_push_table(r->headers_out.headers); |
871 if (ch == NULL) { | 873 if (ch == NULL) { |
872 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 874 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
873 return; | 875 return; |
874 } | 876 } |
875 | 877 |
876 *ch = ph[i]; | 878 *ch = h[i]; |
877 | 879 |
878 /* | 880 /* |
879 * ngx_http_header_filter() output the following headers | 881 * ngx_http_header_filter() output the following headers |
880 * from r->headers_out.headers if they are set: | 882 * from r->headers_out.headers if they are set: |
881 * r->headers_out.server, | 883 * r->headers_out.server, |
882 * r->headers_out.date, | 884 * r->headers_out.date, |
883 * r->headers_out.content_length | 885 * r->headers_out.content_length |
884 */ | 886 */ |
885 | 887 |
886 if (&ph[i] == p->headers_in.server) { | 888 if (&h[i] == p->headers_in.server) { |
887 r->headers_out.server = ch; | 889 r->headers_out.server = ch; |
888 continue; | 890 continue; |
889 } | 891 } |
890 | 892 |
891 if (&ph[i] == p->headers_in.date) { | 893 if (&h[i] == p->headers_in.date) { |
892 r->headers_out.date = ch; | 894 r->headers_out.date = ch; |
893 continue; | 895 continue; |
894 } | 896 } |
895 | 897 |
896 if (&ph[i] == p->headers_in.content_length) { | 898 if (&h[i] == p->headers_in.content_length) { |
897 | 899 |
898 r->headers_out.content_length_n = | 900 r->headers_out.content_length_n = |
899 ngx_atoi(p->headers_in.content_length->value.data, | 901 ngx_atoi(p->headers_in.content_length->value.data, |
900 p->headers_in.content_length->value.len); | 902 p->headers_in.content_length->value.len); |
901 r->headers_out.content_length = ch; | 903 r->headers_out.content_length = ch; |
974 | 976 |
975 } else { | 977 } else { |
976 ep->cyclic_temp_file = 0; | 978 ep->cyclic_temp_file = 0; |
977 r->sendfile = 1; | 979 r->sendfile = 1; |
978 } | 980 } |
981 | |
982 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
983 | |
984 ep->read_timeout = p->lcf->read_timeout; | |
985 ep->send_timeout = clcf->send_timeout; | |
986 ep->send_lowat = clcf->send_lowat; | |
979 | 987 |
980 p->event_pipe = ep; | 988 p->event_pipe = ep; |
981 | 989 |
982 p->upstream.connection->read->event_handler = ngx_http_proxy_process_body; | 990 p->upstream.connection->read->event_handler = ngx_http_proxy_process_body; |
983 r->connection->write->event_handler = ngx_http_proxy_process_body; | 991 r->connection->write->event_handler = ngx_http_proxy_process_body; |