Mercurial > hg > nginx-vendor-0-5
comparison src/http/ngx_http_upstream.c @ 64:5db440287648 NGINX_0_1_32
nginx 0.1.32
*) Bugfix: the arguments were omitted in the redirects, issued by the
"rewrite" directive; bug appeared in 0.1.29.
*) Feature: the "if" directive supports the captures in regular
expressions.
*) Feature: the "set" directive supports the variables and the captures
of regular expressions.
*) Feature: the "X-Accel-Redirect" response header line is supported in
proxy and FastCGI mode.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 19 May 2005 00:00:00 +0400 |
parents | df7d3fff122b |
children | 77969b24f355 |
comparison
equal
deleted
inserted
replaced
63:e42867135781 | 64:5db440287648 |
---|---|
75 ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { | 75 ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { |
76 | 76 |
77 { ngx_string("Status"), | 77 { ngx_string("Status"), |
78 ngx_http_upstream_process_header_line, | 78 ngx_http_upstream_process_header_line, |
79 offsetof(ngx_http_upstream_headers_in_t, status), | 79 offsetof(ngx_http_upstream_headers_in_t, status), |
80 /* STUB */ ngx_http_upstream_ignore_header_line, 0 }, | 80 /* STUB */ ngx_http_upstream_ignore_header_line, 0, 0 }, |
81 | 81 |
82 { ngx_string("Content-Type"), | 82 { ngx_string("Content-Type"), |
83 ngx_http_upstream_process_header_line, | 83 ngx_http_upstream_process_header_line, |
84 offsetof(ngx_http_upstream_headers_in_t, content_type), | 84 offsetof(ngx_http_upstream_headers_in_t, content_type), |
85 ngx_http_upstream_copy_content_type, 0 }, | 85 ngx_http_upstream_copy_content_type, 0, 0 }, |
86 | 86 |
87 { ngx_string("Content-Length"), | 87 { ngx_string("Content-Length"), |
88 ngx_http_upstream_process_header_line, | 88 ngx_http_upstream_process_header_line, |
89 offsetof(ngx_http_upstream_headers_in_t, content_length), | 89 offsetof(ngx_http_upstream_headers_in_t, content_length), |
90 ngx_http_upstream_copy_content_length, 0 }, | 90 ngx_http_upstream_copy_content_length, 0, 0 }, |
91 | 91 |
92 { ngx_string("Date"), | 92 { ngx_string("Date"), |
93 ngx_http_upstream_process_header_line, | 93 ngx_http_upstream_process_header_line, |
94 offsetof(ngx_http_upstream_headers_in_t, date), | 94 offsetof(ngx_http_upstream_headers_in_t, date), |
95 ngx_http_upstream_conditional_copy_header_line, | 95 ngx_http_upstream_conditional_copy_header_line, |
96 offsetof(ngx_http_upstream_conf_t, pass_date) }, | 96 offsetof(ngx_http_upstream_conf_t, pass_date), 0 }, |
97 | 97 |
98 { ngx_string("Server"), | 98 { ngx_string("Server"), |
99 ngx_http_upstream_process_header_line, | 99 ngx_http_upstream_process_header_line, |
100 offsetof(ngx_http_upstream_headers_in_t, server), | 100 offsetof(ngx_http_upstream_headers_in_t, server), |
101 ngx_http_upstream_conditional_copy_header_line, | 101 ngx_http_upstream_conditional_copy_header_line, |
102 offsetof(ngx_http_upstream_conf_t, pass_server) }, | 102 offsetof(ngx_http_upstream_conf_t, pass_server), 0 }, |
103 | 103 |
104 { ngx_string("Location"), | 104 { ngx_string("Location"), |
105 ngx_http_upstream_ignore_header_line, 0, | 105 ngx_http_upstream_ignore_header_line, 0, |
106 ngx_http_upstream_rewrite_location, 0 }, | 106 ngx_http_upstream_rewrite_location, 0, 0 }, |
107 | 107 |
108 { ngx_string("Refresh"), | 108 { ngx_string("Refresh"), |
109 ngx_http_upstream_ignore_header_line, 0, | 109 ngx_http_upstream_ignore_header_line, 0, |
110 ngx_http_upstream_rewrite_refresh, 0 }, | 110 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
111 | |
112 { ngx_string("Set-Cookie"), | |
113 ngx_http_upstream_ignore_header_line, 0, | |
114 ngx_http_upstream_copy_header_line, 0, 1 }, | |
111 | 115 |
112 { ngx_string("Cache-Control"), | 116 { ngx_string("Cache-Control"), |
113 ngx_http_upstream_process_multi_header_lines, | 117 ngx_http_upstream_process_multi_header_lines, |
114 offsetof(ngx_http_upstream_headers_in_t, cache_control), | 118 offsetof(ngx_http_upstream_headers_in_t, cache_control), |
115 ngx_http_upstream_copy_multi_header_lines, | 119 ngx_http_upstream_copy_multi_header_lines, |
116 offsetof(ngx_http_headers_out_t, cache_control) }, | 120 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
117 | 121 |
118 { ngx_string("Connection"), | 122 { ngx_string("Connection"), |
119 ngx_http_upstream_ignore_header_line, 0, | 123 ngx_http_upstream_ignore_header_line, 0, |
120 ngx_http_upstream_ignore_header_line, 0 }, | 124 ngx_http_upstream_ignore_header_line, 0, 0 }, |
121 | 125 |
122 { ngx_string("X-Pad"), | 126 { ngx_string("X-Pad"), |
123 ngx_http_upstream_ignore_header_line, 0, | 127 ngx_http_upstream_ignore_header_line, 0, |
124 ngx_http_upstream_ignore_header_line, 0 }, | 128 ngx_http_upstream_ignore_header_line, 0, 0 }, |
125 | 129 |
126 { ngx_string("X-Powered-By"), | 130 { ngx_string("X-Powered-By"), |
127 ngx_http_upstream_ignore_header_line, 0, | 131 ngx_http_upstream_ignore_header_line, 0, |
128 ngx_http_upstream_conditional_copy_header_line, | 132 ngx_http_upstream_conditional_copy_header_line, |
129 offsetof(ngx_http_upstream_conf_t, pass_x_powered_by) }, | 133 offsetof(ngx_http_upstream_conf_t, pass_x_powered_by), 0 }, |
130 | 134 |
131 { ngx_string("X-Accel-Expires"), | 135 { ngx_string("X-Accel-Expires"), |
132 ngx_http_upstream_process_header_line, | 136 ngx_http_upstream_process_header_line, |
133 offsetof(ngx_http_upstream_headers_in_t, x_accel_expires), | 137 offsetof(ngx_http_upstream_headers_in_t, x_accel_expires), |
134 ngx_http_upstream_conditional_copy_header_line, | 138 ngx_http_upstream_conditional_copy_header_line, |
135 offsetof(ngx_http_upstream_conf_t, pass_x_accel_expires) }, | 139 offsetof(ngx_http_upstream_conf_t, pass_x_accel_expires), 0 }, |
140 | |
141 { ngx_string("X-Accel-Redirect"), | |
142 ngx_http_upstream_process_header_line, | |
143 offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect), | |
144 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
136 | 145 |
137 #if (NGX_HTTP_GZIP) | 146 #if (NGX_HTTP_GZIP) |
138 { ngx_string("Content-Encoding"), | 147 { ngx_string("Content-Encoding"), |
139 ngx_http_upstream_process_header_line, | 148 ngx_http_upstream_process_header_line, |
140 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | 149 offsetof(ngx_http_upstream_headers_in_t, content_encoding), |
141 ngx_http_upstream_copy_content_encoding, 0 }, | 150 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
142 #endif | 151 #endif |
143 | 152 |
144 { ngx_null_string, NULL, 0, NULL, 0 } | 153 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
145 }; | 154 }; |
146 | 155 |
147 | 156 |
148 ngx_http_module_t ngx_http_upstream_module_ctx = { | 157 ngx_http_module_t ngx_http_upstream_module_ctx = { |
149 ngx_http_upstream_add_log_formats, /* preconfiguration */ | 158 ngx_http_upstream_add_log_formats, /* preconfiguration */ |
696 | 705 |
697 | 706 |
698 static void | 707 static void |
699 ngx_http_upstream_process_header(ngx_event_t *rev) | 708 ngx_http_upstream_process_header(ngx_event_t *rev) |
700 { | 709 { |
701 ssize_t n; | 710 ssize_t n; |
702 ngx_int_t rc; | 711 ngx_int_t rc; |
703 ngx_uint_t i; | 712 ngx_uint_t i, key; |
704 ngx_connection_t *c; | 713 ngx_list_part_t *part; |
705 ngx_http_request_t *r; | 714 ngx_table_elt_t *h; |
706 ngx_http_upstream_t *u; | 715 ngx_connection_t *c; |
707 ngx_http_err_page_t *err_page; | 716 ngx_http_request_t *r; |
708 ngx_http_core_loc_conf_t *clcf; | 717 ngx_http_upstream_t *u; |
718 ngx_http_err_page_t *err_page; | |
719 ngx_http_core_loc_conf_t *clcf; | |
720 ngx_http_upstream_header_t *hh; | |
721 ngx_http_upstream_main_conf_t *umcf; | |
709 | 722 |
710 c = rev->data; | 723 c = rev->data; |
711 r = c->data; | 724 r = c->data; |
712 u = r->upstream; | 725 u = r->upstream; |
713 | 726 |
871 r->headers_out.status); | 884 r->headers_out.status); |
872 return; | 885 return; |
873 } | 886 } |
874 } | 887 } |
875 } | 888 } |
889 } | |
890 | |
891 if (r->upstream->headers_in.x_accel_redirect) { | |
892 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); | |
893 | |
894 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
895 hh = (ngx_http_upstream_header_t *) umcf->headers_in_hash.buckets; | |
896 | |
897 part = &r->upstream->headers_in.headers.part; | |
898 h = part->elts; | |
899 | |
900 for (i = 0; /* void */; i++) { | |
901 | |
902 if (i >= part->nelts) { | |
903 if (part->next == NULL) { | |
904 break; | |
905 } | |
906 | |
907 part = part->next; | |
908 h = part->elts; | |
909 i = 0; | |
910 } | |
911 | |
912 key = h[i].hash % umcf->headers_in_hash.hash_size; | |
913 | |
914 if (hh[key].redirect | |
915 && hh[key].name.len == h[i].key.len | |
916 && ngx_strcasecmp(hh[key].name.data, h[i].key.data) == 0) | |
917 { | |
918 if (hh[key].copy_handler(r, &h[i], hh[key].conf) != NGX_OK) { | |
919 ngx_http_upstream_finalize_request(r, u, | |
920 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
921 return; | |
922 } | |
923 | |
924 } | |
925 } | |
926 | |
927 ngx_http_internal_redirect(r, | |
928 &r->upstream->headers_in.x_accel_redirect->value, | |
929 NULL); | |
930 return; | |
876 } | 931 } |
877 | 932 |
878 ngx_http_upstream_send_response(r, u); | 933 ngx_http_upstream_send_response(r, u); |
879 } | 934 } |
880 | 935 |
1305 u->cache->ctx.file.fd); | 1360 u->cache->ctx.file.fd); |
1306 } | 1361 } |
1307 #endif | 1362 #endif |
1308 | 1363 |
1309 r->log_handler = u->saved_log_handler; | 1364 r->log_handler = u->saved_log_handler; |
1365 | |
1366 if (rc == NGX_DECLINED) { | |
1367 return; | |
1368 } | |
1369 | |
1310 r->connection->log->action = "sending to client"; | 1370 r->connection->log->action = "sending to client"; |
1311 | 1371 |
1312 if (rc == 0 && r->main == NULL) { | 1372 if (rc == 0 && r->main == NULL) { |
1313 rc = ngx_http_send_last(r); | 1373 rc = ngx_http_send_last(r); |
1314 } | 1374 } |