comparison src/http/ngx_http_upstream.c @ 294:27d9d1f26b38 NGINX_0_5_17

nginx 0.5.17 *) Change: now nginx always returns the 405 status for the TRACE method. *) Feature: now nginx supports the "include" directive inside the "types" block. *) Bugfix: the $document_root variable usage in the "root" and "alias" directives is disabled: this caused recursive stack overflow. *) Bugfix: in the HTTPS protocol in the "proxy_pass" directive. *) Bugfix: in some cases non-cachable variables (such as $uri variable) returned old cached value.
author Igor Sysoev <http://sysoev.ru>
date Mon, 02 Apr 2007 00:00:00 +0400
parents 92402f034b28
children 2ceaee987f37
comparison
equal deleted inserted replaced
293:30378812e3af 294:27d9d1f26b38
19 ngx_http_upstream_t *u); 19 ngx_http_upstream_t *u);
20 static void ngx_http_upstream_send_request(ngx_http_request_t *r, 20 static void ngx_http_upstream_send_request(ngx_http_request_t *r,
21 ngx_http_upstream_t *u); 21 ngx_http_upstream_t *u);
22 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); 22 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev);
23 static void ngx_http_upstream_process_header(ngx_event_t *rev); 23 static void ngx_http_upstream_process_header(ngx_event_t *rev);
24 static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c);
24 static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev); 25 static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev);
25 static void ngx_http_upstream_send_response(ngx_http_request_t *r, 26 static void ngx_http_upstream_send_response(ngx_http_request_t *r,
26 ngx_http_upstream_t *u); 27 ngx_http_upstream_t *u);
27 static void 28 static void
28 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r); 29 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r);
755 756
756 757
757 static void 758 static void
758 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u) 759 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
759 { 760 {
760 int rc, err; 761 ngx_int_t rc;
761 socklen_t len;
762 ngx_connection_t *c; 762 ngx_connection_t *c;
763 763
764 c = u->peer.connection; 764 c = u->peer.connection;
765 765
766 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 766 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
767 "http upstream send request"); 767 "http upstream send request");
768 768
769 if (!u->request_sent) { 769 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
770 770 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
771 #if (NGX_HAVE_KQUEUE) 771 return;
772
773 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
774 if (c->write->pending_eof) {
775 (void) ngx_connection_error(c, c->write->kq_errno,
776 "kevent() reported that connect() failed");
777 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
778 return;
779 }
780
781 } else
782 #endif
783 {
784 err = 0;
785 len = sizeof(int);
786
787 /*
788 * BSDs and Linux return 0 and set a pending error in err
789 * Solaris returns -1 and sets errno
790 */
791
792 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
793 == -1)
794 {
795 err = ngx_errno;
796 }
797
798 if (err) {
799 (void) ngx_connection_error(c, err, "connect() failed");
800 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
801 return;
802 }
803 }
804 } 772 }
805 773
806 c->log->action = "sending request to upstream"; 774 c->log->action = "sending request to upstream";
807 775
808 rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs); 776 rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs);
943 if (rev->timedout) { 911 if (rev->timedout) {
944 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); 912 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
945 return; 913 return;
946 } 914 }
947 915
916 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
917 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
918 return;
919 }
920
948 if (u->buffer.start == NULL) { 921 if (u->buffer.start == NULL) {
949 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); 922 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);
950 if (u->buffer.start == NULL) { 923 if (u->buffer.start == NULL) {
951 ngx_http_upstream_finalize_request(r, u, 924 ngx_http_upstream_finalize_request(r, u,
952 NGX_HTTP_INTERNAL_SERVER_ERROR); 925 NGX_HTTP_INTERNAL_SERVER_ERROR);
1272 } 1245 }
1273 1246
1274 rev->handler = ngx_http_upstream_process_body_in_memory; 1247 rev->handler = ngx_http_upstream_process_body_in_memory;
1275 1248
1276 ngx_http_upstream_process_body_in_memory(rev); 1249 ngx_http_upstream_process_body_in_memory(rev);
1250 }
1251
1252
1253 static ngx_int_t
1254 ngx_http_upstream_test_connect(ngx_connection_t *c)
1255 {
1256 int err;
1257 socklen_t len;
1258
1259 #if (NGX_HAVE_KQUEUE)
1260
1261 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1262 if (c->write->pending_eof) {
1263 (void) ngx_connection_error(c, c->write->kq_errno,
1264 "kevent() reported that connect() failed");
1265 return NGX_ERROR;
1266 }
1267
1268 } else
1269 #endif
1270 {
1271 err = 0;
1272 len = sizeof(int);
1273
1274 /*
1275 * BSDs and Linux return 0 and set a pending error in err
1276 * Solaris returns -1 and sets errno
1277 */
1278
1279 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
1280 == -1)
1281 {
1282 err = ngx_errno;
1283 }
1284
1285 if (err) {
1286 (void) ngx_connection_error(c, err, "connect() failed");
1287 return NGX_ERROR;
1288 }
1289 }
1290
1291 return NGX_OK;
1277 } 1292 }
1278 1293
1279 1294
1280 static void 1295 static void
1281 ngx_http_upstream_process_body_in_memory(ngx_event_t *rev) 1296 ngx_http_upstream_process_body_in_memory(ngx_event_t *rev)