comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 257:70e1c7d2b83d

nginx-0.0.2-2004-02-11-20:08:49 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Feb 2004 17:08:49 +0000
parents 8dee38ea9117
children 35a6a9df2d25
comparison
equal deleted inserted replaced
256:8e39cab6abd5 257:70e1c7d2b83d
190 h->last = ngx_cpymem(h->last, header[i].value.data, 190 h->last = ngx_cpymem(h->last, header[i].value.data,
191 header[i].value.len); 191 header[i].value.len);
192 192
193 *(h->last++) = CR; *(h->last++) = LF; 193 *(h->last++) = CR; *(h->last++) = LF;
194 194
195 ngx_log_debug(r->connection->log, "proxy: '%s: %s'" _ 195 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
196 header[i].key.data _ header[i].value.data); 196 "http proxy header: \"%s: %s\"",
197 header[i].key.data, header[i].value.data);
197 } 198 }
198 199
199 /* add "\r\n" at the header end */ 200 /* add "\r\n" at the header end */
200 *(h->last++) = CR; *(h->last++) = LF; 201 *(h->last++) = CR; *(h->last++) = LF;
201 202
202 /* STUB */ *(h->last) = '\0'; 203 #if (NGX_DEBUG)
203 ngx_log_debug(r->connection->log, "PROXY:\n'%s'" _ h->pos); 204 *(h->last) = '\0';
205 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
206 "http proxy header:\n\"%s\"", h->pos);
207 #endif
204 208
205 return chain; 209 return chain;
206 } 210 }
207 211
208 212
216 ngx_chain_writer_ctx_t *wctx; 220 ngx_chain_writer_ctx_t *wctx;
217 ngx_http_proxy_log_ctx_t *lctx; 221 ngx_http_proxy_log_ctx_t *lctx;
218 222
219 r = p->request; 223 r = p->request;
220 224
221 ngx_log_debug(r->connection->log, "timer_set: %d" _ 225 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
222 r->connection->read->timer_set); 226 "http proxy set timer: %d",
227 r->connection->read->timer_set);
223 228
224 if (r->connection->read->timer_set) { 229 if (r->connection->read->timer_set) {
225 ngx_del_timer(r->connection->read); 230 ngx_del_timer(r->connection->read);
226 } 231 }
227 232
586 } 591 }
587 592
588 593
589 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev) 594 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev)
590 { 595 {
591 ngx_log_debug(wev->log, "dummy handler"); 596 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http proxy dummy handler");
592 } 597 }
593 598
594 599
595 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev) 600 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
596 { 601 {
601 606
602 c = rev->data; 607 c = rev->data;
603 p = c->data; 608 p = c->data;
604 p->action = "reading upstream status line"; 609 p->action = "reading upstream status line";
605 610
606 ngx_log_debug(rev->log, "http proxy process status line"); 611 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
612 "http proxy process status line");
607 613
608 if (rev->timedout) { 614 if (rev->timedout) {
609 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT); 615 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT);
610 return; 616 return;
611 } 617 }
715 return; 721 return;
716 } 722 }
717 ngx_cpystrn(p->upstream->status_line.data, p->status_start, 723 ngx_cpystrn(p->upstream->status_line.data, p->status_start,
718 p->upstream->status_line.len + 1); 724 p->upstream->status_line.len + 1);
719 725
720 ngx_log_debug(rev->log, "http proxy status %d '%s'" _ 726 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
721 p->upstream->status _ p->upstream->status_line.data); 727 "http proxy status %d \"%s\"",
728 p->upstream->status, p->upstream->status_line.data);
722 729
723 if (p->upstream->headers_in.headers) { 730 if (p->upstream->headers_in.headers) {
724 p->upstream->headers_in.headers->nelts = 0; 731 p->upstream->headers_in.headers->nelts = 0;
725 } else { 732 } else {
726 /* TODO: ngx_init_table */ 733 /* TODO: ngx_init_table */
745 c = rev->data; 752 c = rev->data;
746 p = c->data; 753 p = c->data;
747 r = p->request; 754 r = p->request;
748 p->action = "reading upstream headers"; 755 p->action = "reading upstream headers";
749 756
750 ngx_log_debug(rev->log, "http proxy process header line"); 757 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
758 "http proxy process header line");
751 759
752 if (rev->timedout) { 760 if (rev->timedout) {
753 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT); 761 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT);
754 return; 762 return;
755 } 763 }
816 + ngx_http_proxy_headers_in[i].offset)) = h; 824 + ngx_http_proxy_headers_in[i].offset)) = h;
817 break; 825 break;
818 } 826 }
819 } 827 }
820 828
821 ngx_log_debug(c->log, "HTTP proxy header: '%s: %s'" _ 829 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
822 h->key.data _ h->value.data); 830 "http proxy header: \"%s: %s\"",
831 h->key.data, h->value.data);
823 832
824 continue; 833 continue;
825 834
826 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { 835 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
827 836
828 /* a whole header has been parsed successfully */ 837 /* a whole header has been parsed successfully */
829 838
830 ngx_log_debug(c->log, "HTTP header done"); 839 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
840 "http proxy header done");
831 841
832 /* TODO: hook to process the upstream header */ 842 /* TODO: hook to process the upstream header */
833 843
834 if (p->cachable) { 844 if (p->cachable) {
835 p->cachable = ngx_http_proxy_is_cachable(p); 845 p->cachable = ngx_http_proxy_is_cachable(p);
1070 ngx_event_pipe_t *ep; 1080 ngx_event_pipe_t *ep;
1071 1081
1072 c = ev->data; 1082 c = ev->data;
1073 1083
1074 if (ev->write) { 1084 if (ev->write) {
1075 ngx_log_debug(ev->log, "http proxy process downstream"); 1085 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
1086 "http proxy process downstream");
1076 r = c->data; 1087 r = c->data;
1077 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module); 1088 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1078 p->action = "sending to client"; 1089 p->action = "sending to client";
1079 1090
1080 } else { 1091 } else {
1081 ngx_log_debug(ev->log, "http proxy process upstream"); 1092 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
1093 "http proxy process upstream");
1082 p = c->data; 1094 p = c->data;
1083 r = p->request; 1095 r = p->request;
1084 p->action = "reading upstream body"; 1096 p->action = "reading upstream body";
1085 } 1097 }
1086 1098
1123 return; 1135 return;
1124 } 1136 }
1125 } 1137 }
1126 1138
1127 if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) { 1139 if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
1128 ngx_log_debug(ev->log, "http proxy upstream exit"); 1140 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
1141 "http proxy upstream exit");
1129 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); 1142 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
1130 ngx_http_proxy_finalize_request(p, 0); 1143 ngx_http_proxy_finalize_request(p, 0);
1131 return; 1144 return;
1132 } 1145 }
1133 } 1146 }
1134 1147
1135 if (ep->downstream_error) { 1148 if (ep->downstream_error) {
1136 ngx_log_debug(ev->log, "http proxy downstream error"); 1149 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
1150 "http proxy downstream error");
1137 if (!p->cachable && p->upstream->peer.connection) { 1151 if (!p->cachable && p->upstream->peer.connection) {
1138 ngx_http_proxy_finalize_request(p, 0); 1152 ngx_http_proxy_finalize_request(p, 0);
1139 } 1153 }
1140 } 1154 }
1141
1142 #if 0
1143 if (ep->downstream_done) {
1144 ngx_log_debug(ev->log, "http proxy downstream done");
1145 ngx_http_proxy_finalize_request(p, 0);
1146 return;
1147 }
1148
1149 if (ep->downstream_error) {
1150 ngx_log_debug(ev->log, "http proxy downstream error");
1151 if (!p->cachable && p->upstream->peer.connection) {
1152 ngx_http_proxy_close_connection(p);
1153 }
1154
1155 if (p->upstream->peer.connection == NULL) {
1156 ngx_http_close_request(r);
1157 }
1158 }
1159 #endif
1160 } 1155 }
1161 1156
1162 1157
1163 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type) 1158 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type)
1164 { 1159 {
1165 int status; 1160 int status;
1166 1161
1167 ngx_log_debug(p->request->connection->log, "next upstream: %d" _ ft_type); 1162 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
1163 "http proxy next upstream: %d", ft_type);
1168 1164
1169 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); 1165 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
1170 1166
1171 if (ft_type != NGX_HTTP_PROXY_FT_HTTP_404) { 1167 if (ft_type != NGX_HTTP_PROXY_FT_HTTP_404) {
1172 ngx_event_connect_peer_failed(&p->upstream->peer); 1168 ngx_event_connect_peer_failed(&p->upstream->peer);