comparison src/http/ngx_http_upstream.c @ 36:a39d1b793287 NGINX_0_1_18

nginx 0.1.18 *) Workaround: the default values of the devpoll_events and the devpoll_changes directives changed from 512 to 32 to be compatible with Solaris 10. *) Bugfix: the proxy_set_x_var and fastcgi_set_var directives were not inherited. *) Bugfix: in the redirect rewrite directive the arguments were concatenated with URI by the "&" rather than the "?". *) Bugfix: the lines without trailing ";" in the file being included by the ngx_http_geo_module were silently ignored. *) Feature: the ngx_http_stub_status_module. *) Bugfix: the unknown log format in the access_log directive caused the segmentation fault. *) Feature: the new "document_root" parameter of the fastcgi_params directive. *) Feature: the fastcgi_redirect_errors directive. *) Feature: the new "break" modifier of the "rewrite" directive allows to stop the rewrite/location cycle and sets the current configuration to the request.
author Igor Sysoev <http://sysoev.ru>
date Wed, 09 Feb 2005 00:00:00 +0300
parents aab2ea7c0458
children 72eb30262aac
comparison
equal deleted inserted replaced
35:ef53675fe4a6 36:a39d1b793287
10 #include <ngx_event_connect.h> 10 #include <ngx_event_connect.h>
11 11
12 12
13 static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev); 13 static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev);
14 static void ngx_http_upstream_connect(ngx_http_request_t *r, 14 static void ngx_http_upstream_connect(ngx_http_request_t *r,
15 ngx_http_upstream_t *u); 15 ngx_http_upstream_t *u);
16 static void ngx_http_upstream_reinit(ngx_http_request_t *r, 16 static void ngx_http_upstream_reinit(ngx_http_request_t *r,
17 ngx_http_upstream_t *u); 17 ngx_http_upstream_t *u);
18 static void ngx_http_upstream_send_request(ngx_http_request_t *r, 18 static void ngx_http_upstream_send_request(ngx_http_request_t *r,
19 ngx_http_upstream_t *u); 19 ngx_http_upstream_t *u);
20 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); 20 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev);
21 static void ngx_http_upstream_process_header(ngx_event_t *rev); 21 static void ngx_http_upstream_process_header(ngx_event_t *rev);
22 static void ngx_http_upstream_send_response(ngx_http_request_t *r, 22 static void ngx_http_upstream_send_response(ngx_http_request_t *r,
23 ngx_http_upstream_t *u); 23 ngx_http_upstream_t *u);
24 static void ngx_http_upstream_process_body(ngx_event_t *ev); 24 static void ngx_http_upstream_process_body(ngx_event_t *ev);
25 static void ngx_http_upstream_dummy_handler(ngx_event_t *wev); 25 static void ngx_http_upstream_dummy_handler(ngx_event_t *wev);
26 static void ngx_http_upstream_next(ngx_http_request_t *r, 26 static void ngx_http_upstream_next(ngx_http_request_t *r,
27 ngx_http_upstream_t *u, 27 ngx_http_upstream_t *u, ngx_uint_t ft_type);
28 ngx_uint_t ft_type);
29 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, 28 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
30 ngx_http_upstream_t *u, 29 ngx_http_upstream_t *u, ngx_int_t rc);
31 ngx_int_t rc);
32 30
33 static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, 31 static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r,
34 uintptr_t data); 32 uintptr_t data);
35 static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, 33 static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r,
36 ngx_http_log_op_t *op); 34 u_char *buf, ngx_http_log_op_t *op);
37
38 35
39 static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf); 36 static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf);
40 37
41 38
42 ngx_http_module_t ngx_http_upstream_module_ctx = { 39 ngx_http_module_t ngx_http_upstream_module_ctx = {
75 "upstream sent invalid header", 72 "upstream sent invalid header",
76 "upstream sent too long header line" 73 "upstream sent too long header line"
77 }; 74 };
78 75
79 76
80 void ngx_http_upstream_init(ngx_http_request_t *r) 77 void
78 ngx_http_upstream_init(ngx_http_request_t *r)
81 { 79 {
82 ngx_connection_t *c; 80 ngx_connection_t *c;
83 ngx_http_upstream_t *u; 81 ngx_http_upstream_t *u;
84 82
85 c = r->connection; 83 c = r->connection;
146 144
147 ngx_http_upstream_connect(r, u); 145 ngx_http_upstream_connect(r, u);
148 } 146 }
149 147
150 148
151 static void ngx_http_upstream_check_broken_connection(ngx_event_t *ev) 149 static void
150 ngx_http_upstream_check_broken_connection(ngx_event_t *ev)
152 { 151 {
153 int n; 152 int n;
154 char buf[1]; 153 char buf[1];
155 ngx_err_t err; 154 ngx_err_t err;
156 ngx_connection_t *c; 155 ngx_connection_t *c;
263 return; 262 return;
264 } 263 }
265 } 264 }
266 265
267 266
268 static void ngx_http_upstream_connect(ngx_http_request_t *r, 267 static void
269 ngx_http_upstream_t *u) 268 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
270 { 269 {
271 ngx_int_t rc; 270 ngx_int_t rc;
272 ngx_connection_t *c; 271 ngx_connection_t *c;
273 272
274 r->connection->log->action = "connecting to upstream"; 273 r->connection->log->action = "connecting to upstream";
348 347
349 ngx_http_upstream_send_request(r, u); 348 ngx_http_upstream_send_request(r, u);
350 } 349 }
351 350
352 351
353 static void ngx_http_upstream_reinit(ngx_http_request_t *r, 352 static void
354 ngx_http_upstream_t *u) 353 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
355 { 354 {
356 ngx_chain_t *cl; 355 ngx_chain_t *cl;
357 356
358 if (u->reinit_request(r) == NGX_ERROR) { 357 if (u->reinit_request(r) == NGX_ERROR) {
359 ngx_http_upstream_finalize_request(r, u, 358 ngx_http_upstream_finalize_request(r, u,
398 NGX_HTTP_INTERNAL_SERVER_ERROR); 397 NGX_HTTP_INTERNAL_SERVER_ERROR);
399 return; 398 return;
400 } 399 }
401 400
402 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); 401 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
403 402 }
404 u->status = 0; 403
405 u->status_count = 0; 404
406 } 405 static void
407 406 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
408
409 static void ngx_http_upstream_send_request(ngx_http_request_t *r,
410 ngx_http_upstream_t *u)
411 { 407 {
412 int rc; 408 int rc;
413 ngx_connection_t *c; 409 ngx_connection_t *c;
414 410
415 c = u->peer.connection; 411 c = u->peer.connection;
503 return; 499 return;
504 } 500 }
505 } 501 }
506 502
507 503
508 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev) 504 static void
505 ngx_http_upstream_send_request_handler(ngx_event_t *wev)
509 { 506 {
510 ngx_connection_t *c; 507 ngx_connection_t *c;
511 ngx_http_request_t *r; 508 ngx_http_request_t *r;
512 ngx_http_upstream_t *u; 509 ngx_http_upstream_t *u;
513 510
532 529
533 ngx_http_upstream_send_request(r, u); 530 ngx_http_upstream_send_request(r, u);
534 } 531 }
535 532
536 533
537 static void ngx_http_upstream_process_header(ngx_event_t *rev) 534 static void
538 { 535 ngx_http_upstream_process_header(ngx_event_t *rev)
539 ssize_t n; 536 {
540 ngx_int_t rc; 537 ssize_t n;
541 ngx_connection_t *c; 538 ngx_int_t rc;
542 ngx_http_request_t *r; 539 ngx_uint_t i;
543 ngx_http_upstream_t *u; 540 ngx_connection_t *c;
541 ngx_http_request_t *r;
542 ngx_http_upstream_t *u;
543 ngx_http_err_page_t *err_page;
544 ngx_http_core_loc_conf_t *clcf;
544 545
545 c = rev->data; 546 c = rev->data;
546 r = c->data; 547 r = c->data;
547 u = r->upstream; 548 u = r->upstream;
548 549
655 return; 656 return;
656 } 657 }
657 658
658 /* rc == NGX_OK */ 659 /* rc == NGX_OK */
659 660
661 if (r->headers_out.status >= NGX_HTTP_BAD_REQUEST
662 && u->conf->redirect_errors
663 && r->err_ctx == NULL)
664 {
665 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
666
667 if (clcf->error_pages) {
668
669 err_page = clcf->error_pages->elts;
670 for (i = 0; i < clcf->error_pages->nelts; i++) {
671 if (err_page[i].status == (ngx_int_t) r->headers_out.status) {
672 ngx_http_upstream_finalize_request(r, u,
673 r->headers_out.status);
674 return;
675 }
676 }
677 }
678 }
679
660 ngx_http_upstream_send_response(r, u); 680 ngx_http_upstream_send_response(r, u);
661 } 681 }
662 682
663 683
664 static void ngx_http_upstream_send_response(ngx_http_request_t *r, 684 static void
665 ngx_http_upstream_t *u) 685 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
666 { 686 {
667 ngx_int_t rc; 687 ngx_int_t rc;
668 ngx_event_pipe_t *p; 688 ngx_event_pipe_t *p;
669 ngx_http_core_loc_conf_t *clcf; 689 ngx_http_core_loc_conf_t *clcf;
670 690
800 820
801 ngx_http_upstream_process_body(u->peer.connection->read); 821 ngx_http_upstream_process_body(u->peer.connection->read);
802 } 822 }
803 823
804 824
805 static void ngx_http_upstream_process_body(ngx_event_t *ev) 825 static void
826 ngx_http_upstream_process_body(ngx_event_t *ev)
806 { 827 {
807 ngx_connection_t *c; 828 ngx_connection_t *c;
808 ngx_http_request_t *r; 829 ngx_http_request_t *r;
809 ngx_http_upstream_t *u; 830 ngx_http_upstream_t *u;
810 ngx_event_pipe_t *p; 831 ngx_event_pipe_t *p;
889 } 910 }
890 } 911 }
891 } 912 }
892 913
893 914
894 static void ngx_http_upstream_dummy_handler(ngx_event_t *wev) 915 static void
916 ngx_http_upstream_dummy_handler(ngx_event_t *wev)
895 { 917 {
896 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, 918 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
897 "http upstream dummy handler"); 919 "http upstream dummy handler");
898 } 920 }
899 921
900 922
901 static void ngx_http_upstream_next(ngx_http_request_t *r, 923 static void
902 ngx_http_upstream_t *u, 924 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
903 ngx_uint_t ft_type) 925 ngx_uint_t ft_type)
904 { 926 {
905 ngx_uint_t status; 927 ngx_uint_t status;
906 928
907 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 929 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
908 "http next upstream, %xD", ft_type); 930 "http next upstream, %xD", ft_type);
992 1014
993 ngx_http_upstream_connect(r, u); 1015 ngx_http_upstream_connect(r, u);
994 } 1016 }
995 1017
996 1018
997 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, 1019 static void
998 ngx_http_upstream_t *u, 1020 ngx_http_upstream_finalize_request(ngx_http_request_t *r,
999 ngx_int_t rc) 1021 ngx_http_upstream_t *u, ngx_int_t rc)
1000 { 1022 {
1001 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1023 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1002 "finalize http upstream request: %i", rc); 1024 "finalize http upstream request: %i", rc);
1003 1025
1004 u->finalize_request(r, rc); 1026 u->finalize_request(r, rc);
1055 1077
1056 ngx_http_finalize_request(r, rc); 1078 ngx_http_finalize_request(r, rc);
1057 } 1079 }
1058 1080
1059 1081
1060 static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, 1082 static size_t
1061 uintptr_t data) 1083 ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data)
1062 { 1084 {
1063 if (r->upstream) { 1085 if (r->upstream) {
1064 return r->upstream->states.nelts * (3 + 2); 1086 return r->upstream->states.nelts * (3 + 2);
1065 } 1087 }
1066 1088
1067 return 1; 1089 return 1;
1068 } 1090 }
1069 1091
1070 1092
1071 static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, 1093 static u_char *
1072 ngx_http_log_op_t *op) 1094 ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
1095 ngx_http_log_op_t *op)
1073 { 1096 {
1074 ngx_uint_t i; 1097 ngx_uint_t i;
1075 ngx_http_upstream_t *u; 1098 ngx_http_upstream_t *u;
1076 ngx_http_upstream_state_t *state; 1099 ngx_http_upstream_state_t *state;
1077 1100
1101 *buf++ = ' '; 1124 *buf++ = ' ';
1102 } 1125 }
1103 } 1126 }
1104 1127
1105 1128
1106 u_char *ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len) 1129 u_char *
1130 ngx_http_upstream_log_error(ngx_log_t *log, u_char *buf, size_t len)
1107 { 1131 {
1108 u_char *p; 1132 u_char *p;
1109 ngx_int_t escape; 1133 ngx_int_t escape;
1110 ngx_str_t uri; 1134 ngx_str_t uri;
1111 ngx_http_log_ctx_t *ctx; 1135 ngx_http_log_ctx_t *ctx;
1175 return ngx_snprintf(buf, len, "%V%s%V", 1199 return ngx_snprintf(buf, len, "%V%s%V",
1176 &uri, r->args.len ? "?" : "", &r->args); 1200 &uri, r->args.len ? "?" : "", &r->args);
1177 } 1201 }
1178 1202
1179 1203
1180 static ngx_int_t ngx_http_upstream_add_log_formats(ngx_conf_t *cf) 1204 static ngx_int_t
1205 ngx_http_upstream_add_log_formats(ngx_conf_t *cf)
1181 { 1206 {
1182 ngx_http_log_op_name_t *op; 1207 ngx_http_log_op_name_t *op;
1183 1208
1184 for (op = ngx_http_upstream_log_fmt_ops; op->name.len; op++) { /* void */ } 1209 for (op = ngx_http_upstream_log_fmt_ops; op->name.len; op++) { /* void */ }
1185 op->run = NULL; 1210 op->run = NULL;