Mercurial > hg > nginx-ranges
comparison src/http/modules/ngx_http_proxy_module.c @ 635:e67b227c8dbb default tip
Merge with current.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Apr 2011 04:07:55 +0400 |
parents | bb20316269e4 |
children |
comparison
equal
deleted
inserted
replaced
578:f3a9e57d2e17 | 635:e67b227c8dbb |
---|---|
49 ngx_array_t *headers_set_len; | 49 ngx_array_t *headers_set_len; |
50 ngx_array_t *headers_set; | 50 ngx_array_t *headers_set; |
51 ngx_hash_t headers_set_hash; | 51 ngx_hash_t headers_set_hash; |
52 | 52 |
53 ngx_array_t *headers_source; | 53 ngx_array_t *headers_source; |
54 ngx_array_t *headers_names; | |
55 | 54 |
56 ngx_array_t *proxy_lengths; | 55 ngx_array_t *proxy_lengths; |
57 ngx_array_t *proxy_values; | 56 ngx_array_t *proxy_values; |
58 | 57 |
59 ngx_array_t *redirects; | 58 ngx_array_t *redirects; |
76 ngx_uint_t headers_hash_bucket_size; | 75 ngx_uint_t headers_hash_bucket_size; |
77 } ngx_http_proxy_loc_conf_t; | 76 } ngx_http_proxy_loc_conf_t; |
78 | 77 |
79 | 78 |
80 typedef struct { | 79 typedef struct { |
81 ngx_uint_t status; | 80 ngx_http_status_t status; |
82 ngx_uint_t status_count; | |
83 u_char *status_start; | |
84 u_char *status_end; | |
85 | |
86 ngx_http_proxy_vars_t vars; | 81 ngx_http_proxy_vars_t vars; |
87 | |
88 size_t internal_body_length; | 82 size_t internal_body_length; |
89 } ngx_http_proxy_ctx_t; | 83 } ngx_http_proxy_ctx_t; |
90 | |
91 | |
92 #define NGX_HTTP_PROXY_PARSE_NO_HEADER 20 | |
93 | 84 |
94 | 85 |
95 static ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, | 86 static ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, |
96 ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_loc_conf_t *plcf); | 87 ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_loc_conf_t *plcf); |
97 #if (NGX_HTTP_CACHE) | 88 #if (NGX_HTTP_CACHE) |
98 static ngx_int_t ngx_http_proxy_create_key(ngx_http_request_t *r); | 89 static ngx_int_t ngx_http_proxy_create_key(ngx_http_request_t *r); |
99 #endif | 90 #endif |
100 static ngx_int_t ngx_http_proxy_create_request(ngx_http_request_t *r); | 91 static ngx_int_t ngx_http_proxy_create_request(ngx_http_request_t *r); |
101 static ngx_int_t ngx_http_proxy_reinit_request(ngx_http_request_t *r); | 92 static ngx_int_t ngx_http_proxy_reinit_request(ngx_http_request_t *r); |
102 static ngx_int_t ngx_http_proxy_process_status_line(ngx_http_request_t *r); | 93 static ngx_int_t ngx_http_proxy_process_status_line(ngx_http_request_t *r); |
103 static ngx_int_t ngx_http_proxy_parse_status_line(ngx_http_request_t *r, | |
104 ngx_http_proxy_ctx_t *ctx); | |
105 static ngx_int_t ngx_http_proxy_process_header(ngx_http_request_t *r); | 94 static ngx_int_t ngx_http_proxy_process_header(ngx_http_request_t *r); |
106 static void ngx_http_proxy_abort_request(ngx_http_request_t *r); | 95 static void ngx_http_proxy_abort_request(ngx_http_request_t *r); |
107 static void ngx_http_proxy_finalize_request(ngx_http_request_t *r, | 96 static void ngx_http_proxy_finalize_request(ngx_http_request_t *r, |
108 ngx_int_t rc); | 97 ngx_int_t rc); |
109 | 98 |
139 static char *ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, | 128 static char *ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, |
140 void *conf); | 129 void *conf); |
141 #endif | 130 #endif |
142 | 131 |
143 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); | 132 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); |
144 | |
145 static char *ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, | |
146 ngx_command_t *cmd, void *conf); | |
147 static char *ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
148 ngx_command_t *cmd, void *conf); | |
149 | 133 |
150 #if (NGX_HTTP_SSL) | 134 #if (NGX_HTTP_SSL) |
151 static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf, | 135 static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf, |
152 ngx_http_proxy_loc_conf_t *plcf); | 136 ngx_http_proxy_loc_conf_t *plcf); |
153 #endif | 137 #endif |
171 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, | 155 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, |
172 { ngx_null_string, 0 } | 156 { ngx_null_string, 0 } |
173 }; | 157 }; |
174 | 158 |
175 | 159 |
176 static ngx_conf_bitmask_t ngx_http_proxy_ignore_headers_masks[] = { | |
177 { ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT }, | |
178 { ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES }, | |
179 { ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES }, | |
180 { ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL }, | |
181 { ngx_null_string, 0 } | |
182 }; | |
183 | |
184 | |
185 ngx_module_t ngx_http_proxy_module; | 160 ngx_module_t ngx_http_proxy_module; |
186 | 161 |
187 | 162 |
188 static ngx_command_t ngx_http_proxy_commands[] = { | 163 static ngx_command_t ngx_http_proxy_commands[] = { |
189 | 164 |
342 NULL }, | 317 NULL }, |
343 | 318 |
344 #if (NGX_HTTP_CACHE) | 319 #if (NGX_HTTP_CACHE) |
345 | 320 |
346 { ngx_string("proxy_cache"), | 321 { ngx_string("proxy_cache"), |
347 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 322 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
348 ngx_http_proxy_cache, | 323 ngx_http_proxy_cache, |
349 NGX_HTTP_LOC_CONF_OFFSET, | 324 NGX_HTTP_LOC_CONF_OFFSET, |
350 0, | 325 0, |
351 NULL }, | 326 NULL }, |
352 | 327 |
353 { ngx_string("proxy_cache_key"), | 328 { ngx_string("proxy_cache_key"), |
354 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 329 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
355 ngx_http_proxy_cache_key, | 330 ngx_http_proxy_cache_key, |
356 NGX_HTTP_LOC_CONF_OFFSET, | 331 NGX_HTTP_LOC_CONF_OFFSET, |
357 0, | 332 0, |
358 NULL }, | 333 NULL }, |
359 | 334 |
362 ngx_http_file_cache_set_slot, | 337 ngx_http_file_cache_set_slot, |
363 0, | 338 0, |
364 0, | 339 0, |
365 &ngx_http_proxy_module }, | 340 &ngx_http_proxy_module }, |
366 | 341 |
342 { ngx_string("proxy_cache_bypass"), | |
343 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
344 ngx_http_set_predicate_slot, | |
345 NGX_HTTP_LOC_CONF_OFFSET, | |
346 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_bypass), | |
347 NULL }, | |
348 | |
349 { ngx_string("proxy_no_cache"), | |
350 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
351 ngx_http_set_predicate_slot, | |
352 NGX_HTTP_LOC_CONF_OFFSET, | |
353 offsetof(ngx_http_proxy_loc_conf_t, upstream.no_cache), | |
354 NULL }, | |
355 | |
367 { ngx_string("proxy_cache_valid"), | 356 { ngx_string("proxy_cache_valid"), |
368 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | 357 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
369 ngx_http_file_cache_valid_set_slot, | 358 ngx_http_file_cache_valid_set_slot, |
370 NGX_HTTP_LOC_CONF_OFFSET, | 359 NGX_HTTP_LOC_CONF_OFFSET, |
371 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_valid), | 360 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_valid), |
420 ngx_conf_set_bitmask_slot, | 409 ngx_conf_set_bitmask_slot, |
421 NGX_HTTP_LOC_CONF_OFFSET, | 410 NGX_HTTP_LOC_CONF_OFFSET, |
422 offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream), | 411 offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream), |
423 &ngx_http_proxy_next_upstream_masks }, | 412 &ngx_http_proxy_next_upstream_masks }, |
424 | 413 |
425 { ngx_string("proxy_upstream_max_fails"), | 414 { ngx_string("proxy_pass_header"), |
426 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 415 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
427 ngx_http_proxy_upstream_max_fails_unsupported, | 416 ngx_conf_set_str_array_slot, |
428 0, | 417 NGX_HTTP_LOC_CONF_OFFSET, |
429 0, | 418 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_headers), |
430 NULL }, | 419 NULL }, |
431 | 420 |
432 { ngx_string("proxy_upstream_fail_timeout"), | 421 { ngx_string("proxy_hide_header"), |
433 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 422 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
434 ngx_http_proxy_upstream_fail_timeout_unsupported, | |
435 0, | |
436 0, | |
437 NULL }, | |
438 | |
439 { ngx_string("proxy_pass_header"), | |
440 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
441 ngx_conf_set_str_array_slot, | |
442 NGX_HTTP_LOC_CONF_OFFSET, | |
443 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_headers), | |
444 NULL }, | |
445 | |
446 { ngx_string("proxy_hide_header"), | |
447 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
448 ngx_conf_set_str_array_slot, | 423 ngx_conf_set_str_array_slot, |
449 NGX_HTTP_LOC_CONF_OFFSET, | 424 NGX_HTTP_LOC_CONF_OFFSET, |
450 offsetof(ngx_http_proxy_loc_conf_t, upstream.hide_headers), | 425 offsetof(ngx_http_proxy_loc_conf_t, upstream.hide_headers), |
451 NULL }, | 426 NULL }, |
452 | 427 |
453 { ngx_string("proxy_ignore_headers"), | 428 { ngx_string("proxy_ignore_headers"), |
454 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | 429 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
455 ngx_conf_set_bitmask_slot, | 430 ngx_conf_set_bitmask_slot, |
456 NGX_HTTP_LOC_CONF_OFFSET, | 431 NGX_HTTP_LOC_CONF_OFFSET, |
457 offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_headers), | 432 offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_headers), |
458 &ngx_http_proxy_ignore_headers_masks }, | 433 &ngx_http_upstream_ignore_headers_masks }, |
459 | 434 |
460 #if (NGX_HTTP_SSL) | 435 #if (NGX_HTTP_SSL) |
461 | 436 |
462 { ngx_string("proxy_ssl_session_reuse"), | 437 { ngx_string("proxy_ssl_session_reuse"), |
463 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 438 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
542 { ngx_string("Range"), ngx_string("") }, | 517 { ngx_string("Range"), ngx_string("") }, |
543 { ngx_string("If-Range"), ngx_string("") }, | 518 { ngx_string("If-Range"), ngx_string("") }, |
544 { ngx_null_string, ngx_null_string } | 519 { ngx_null_string, ngx_null_string } |
545 }; | 520 }; |
546 | 521 |
547 | |
548 static ngx_str_t ngx_http_proxy_hide_cache_headers[] = { | |
549 ngx_string("Date"), | |
550 ngx_string("Server"), | |
551 ngx_string("X-Pad"), | |
552 ngx_string("X-Accel-Expires"), | |
553 ngx_string("X-Accel-Redirect"), | |
554 ngx_string("X-Accel-Limit-Rate"), | |
555 ngx_string("X-Accel-Buffering"), | |
556 ngx_string("X-Accel-Charset"), | |
557 ngx_string("Set-Cookie"), | |
558 ngx_string("P3P"), | |
559 ngx_null_string | |
560 }; | |
561 | |
562 #endif | 522 #endif |
563 | 523 |
564 | 524 |
565 static ngx_http_variable_t ngx_http_proxy_vars[] = { | 525 static ngx_http_variable_t ngx_http_proxy_vars[] = { |
566 | 526 |
610 | 570 |
611 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | 571 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); |
612 | 572 |
613 u = r->upstream; | 573 u = r->upstream; |
614 | 574 |
615 if (plcf->proxy_lengths == 0) { | 575 if (plcf->proxy_lengths == NULL) { |
616 ctx->vars = plcf->vars; | 576 ctx->vars = plcf->vars; |
617 u->schema = plcf->vars.schema; | 577 u->schema = plcf->vars.schema; |
618 #if (NGX_HTTP_SSL) | 578 #if (NGX_HTTP_SSL) |
619 u->ssl = (plcf->upstream.ssl != NULL); | 579 u->ssl = (plcf->upstream.ssl != NULL); |
620 #endif | 580 #endif |
635 u->create_request = ngx_http_proxy_create_request; | 595 u->create_request = ngx_http_proxy_create_request; |
636 u->reinit_request = ngx_http_proxy_reinit_request; | 596 u->reinit_request = ngx_http_proxy_reinit_request; |
637 u->process_header = ngx_http_proxy_process_status_line; | 597 u->process_header = ngx_http_proxy_process_status_line; |
638 u->abort_request = ngx_http_proxy_abort_request; | 598 u->abort_request = ngx_http_proxy_abort_request; |
639 u->finalize_request = ngx_http_proxy_finalize_request; | 599 u->finalize_request = ngx_http_proxy_finalize_request; |
600 r->state = 0; | |
640 | 601 |
641 if (plcf->redirects) { | 602 if (plcf->redirects) { |
642 u->rewrite_redirect = ngx_http_proxy_rewrite_redirect; | 603 u->rewrite_redirect = ngx_http_proxy_rewrite_redirect; |
643 } | 604 } |
644 | 605 |
921 | 882 |
922 } else { | 883 } else { |
923 loc_len = (r->valid_location && ctx->vars.uri.len) ? | 884 loc_len = (r->valid_location && ctx->vars.uri.len) ? |
924 plcf->location.len : 0; | 885 plcf->location.len : 0; |
925 | 886 |
926 if (r->quoted_uri || r->internal) { | 887 if (r->quoted_uri || r->space_in_uri || r->internal) { |
927 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, | 888 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, |
928 r->uri.len - loc_len, NGX_ESCAPE_URI); | 889 r->uri.len - loc_len, NGX_ESCAPE_URI); |
929 } | 890 } |
930 | 891 |
931 uri_len = ctx->vars.uri.len + r->uri.len - loc_len + escape | 892 uri_len = ctx->vars.uri.len + r->uri.len - loc_len + escape |
1190 | 1151 |
1191 if (ctx == NULL) { | 1152 if (ctx == NULL) { |
1192 return NGX_OK; | 1153 return NGX_OK; |
1193 } | 1154 } |
1194 | 1155 |
1195 ctx->status = 0; | 1156 ctx->status.code = 0; |
1196 ctx->status_count = 0; | 1157 ctx->status.count = 0; |
1197 ctx->status_start = NULL; | 1158 ctx->status.start = NULL; |
1198 ctx->status_end = NULL; | 1159 ctx->status.end = NULL; |
1199 | 1160 |
1200 r->upstream->process_header = ngx_http_proxy_process_status_line; | 1161 r->upstream->process_header = ngx_http_proxy_process_status_line; |
1162 r->state = 0; | |
1201 | 1163 |
1202 return NGX_OK; | 1164 return NGX_OK; |
1203 } | 1165 } |
1204 | 1166 |
1205 | 1167 |
1206 static ngx_int_t | 1168 static ngx_int_t |
1207 ngx_http_proxy_process_status_line(ngx_http_request_t *r) | 1169 ngx_http_proxy_process_status_line(ngx_http_request_t *r) |
1208 { | 1170 { |
1171 size_t len; | |
1209 ngx_int_t rc; | 1172 ngx_int_t rc; |
1210 ngx_http_upstream_t *u; | 1173 ngx_http_upstream_t *u; |
1211 ngx_http_proxy_ctx_t *ctx; | 1174 ngx_http_proxy_ctx_t *ctx; |
1212 | 1175 |
1213 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | 1176 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); |
1214 | 1177 |
1215 if (ctx == NULL) { | 1178 if (ctx == NULL) { |
1216 return NGX_ERROR; | 1179 return NGX_ERROR; |
1217 } | 1180 } |
1218 | 1181 |
1219 rc = ngx_http_proxy_parse_status_line(r, ctx); | 1182 u = r->upstream; |
1183 | |
1184 rc = ngx_http_parse_status_line(r, &u->buffer, &ctx->status); | |
1220 | 1185 |
1221 if (rc == NGX_AGAIN) { | 1186 if (rc == NGX_AGAIN) { |
1222 return rc; | 1187 return rc; |
1223 } | 1188 } |
1224 | 1189 |
1225 u = r->upstream; | 1190 if (rc == NGX_ERROR) { |
1226 | |
1227 if (rc == NGX_HTTP_PROXY_PARSE_NO_HEADER) { | |
1228 | 1191 |
1229 #if (NGX_HTTP_CACHE) | 1192 #if (NGX_HTTP_CACHE) |
1230 | 1193 |
1231 if (r->cache) { | 1194 if (r->cache) { |
1232 r->http_version = NGX_HTTP_VERSION_9; | 1195 r->http_version = NGX_HTTP_VERSION_9; |
1249 | 1212 |
1250 return NGX_OK; | 1213 return NGX_OK; |
1251 } | 1214 } |
1252 | 1215 |
1253 if (u->state) { | 1216 if (u->state) { |
1254 u->state->status = ctx->status; | 1217 u->state->status = ctx->status.code; |
1255 } | 1218 } |
1256 | 1219 |
1257 u->headers_in.status_n = ctx->status; | 1220 u->headers_in.status_n = ctx->status.code; |
1258 | 1221 |
1259 u->headers_in.status_line.len = ctx->status_end - ctx->status_start; | 1222 len = ctx->status.end - ctx->status.start; |
1260 u->headers_in.status_line.data = ngx_pnalloc(r->pool, | 1223 u->headers_in.status_line.len = len; |
1261 u->headers_in.status_line.len); | 1224 |
1225 u->headers_in.status_line.data = ngx_pnalloc(r->pool, len); | |
1262 if (u->headers_in.status_line.data == NULL) { | 1226 if (u->headers_in.status_line.data == NULL) { |
1263 return NGX_ERROR; | 1227 return NGX_ERROR; |
1264 } | 1228 } |
1265 | 1229 |
1266 ngx_memcpy(u->headers_in.status_line.data, ctx->status_start, | 1230 ngx_memcpy(u->headers_in.status_line.data, ctx->status.start, len); |
1267 u->headers_in.status_line.len); | |
1268 | 1231 |
1269 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1232 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1270 "http proxy status %ui \"%V\"", | 1233 "http proxy status %ui \"%V\"", |
1271 u->headers_in.status_n, &u->headers_in.status_line); | 1234 u->headers_in.status_n, &u->headers_in.status_line); |
1272 | 1235 |
1273 u->process_header = ngx_http_proxy_process_header; | 1236 u->process_header = ngx_http_proxy_process_header; |
1274 | 1237 |
1275 return ngx_http_proxy_process_header(r); | 1238 return ngx_http_proxy_process_header(r); |
1276 } | |
1277 | |
1278 | |
1279 static ngx_int_t | |
1280 ngx_http_proxy_parse_status_line(ngx_http_request_t *r, | |
1281 ngx_http_proxy_ctx_t *ctx) | |
1282 { | |
1283 u_char ch; | |
1284 u_char *p; | |
1285 ngx_http_upstream_t *u; | |
1286 enum { | |
1287 sw_start = 0, | |
1288 sw_H, | |
1289 sw_HT, | |
1290 sw_HTT, | |
1291 sw_HTTP, | |
1292 sw_first_major_digit, | |
1293 sw_major_digit, | |
1294 sw_first_minor_digit, | |
1295 sw_minor_digit, | |
1296 sw_status, | |
1297 sw_space_after_status, | |
1298 sw_status_text, | |
1299 sw_almost_done | |
1300 } state; | |
1301 | |
1302 u = r->upstream; | |
1303 | |
1304 state = r->state; | |
1305 | |
1306 for (p = u->buffer.pos; p < u->buffer.last; p++) { | |
1307 ch = *p; | |
1308 | |
1309 switch (state) { | |
1310 | |
1311 /* "HTTP/" */ | |
1312 case sw_start: | |
1313 switch (ch) { | |
1314 case 'H': | |
1315 state = sw_H; | |
1316 break; | |
1317 default: | |
1318 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1319 } | |
1320 break; | |
1321 | |
1322 case sw_H: | |
1323 switch (ch) { | |
1324 case 'T': | |
1325 state = sw_HT; | |
1326 break; | |
1327 default: | |
1328 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1329 } | |
1330 break; | |
1331 | |
1332 case sw_HT: | |
1333 switch (ch) { | |
1334 case 'T': | |
1335 state = sw_HTT; | |
1336 break; | |
1337 default: | |
1338 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1339 } | |
1340 break; | |
1341 | |
1342 case sw_HTT: | |
1343 switch (ch) { | |
1344 case 'P': | |
1345 state = sw_HTTP; | |
1346 break; | |
1347 default: | |
1348 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1349 } | |
1350 break; | |
1351 | |
1352 case sw_HTTP: | |
1353 switch (ch) { | |
1354 case '/': | |
1355 state = sw_first_major_digit; | |
1356 break; | |
1357 default: | |
1358 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1359 } | |
1360 break; | |
1361 | |
1362 /* the first digit of major HTTP version */ | |
1363 case sw_first_major_digit: | |
1364 if (ch < '1' || ch > '9') { | |
1365 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1366 } | |
1367 | |
1368 state = sw_major_digit; | |
1369 break; | |
1370 | |
1371 /* the major HTTP version or dot */ | |
1372 case sw_major_digit: | |
1373 if (ch == '.') { | |
1374 state = sw_first_minor_digit; | |
1375 break; | |
1376 } | |
1377 | |
1378 if (ch < '0' || ch > '9') { | |
1379 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1380 } | |
1381 | |
1382 break; | |
1383 | |
1384 /* the first digit of minor HTTP version */ | |
1385 case sw_first_minor_digit: | |
1386 if (ch < '0' || ch > '9') { | |
1387 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1388 } | |
1389 | |
1390 state = sw_minor_digit; | |
1391 break; | |
1392 | |
1393 /* the minor HTTP version or the end of the request line */ | |
1394 case sw_minor_digit: | |
1395 if (ch == ' ') { | |
1396 state = sw_status; | |
1397 break; | |
1398 } | |
1399 | |
1400 if (ch < '0' || ch > '9') { | |
1401 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1402 } | |
1403 | |
1404 break; | |
1405 | |
1406 /* HTTP status code */ | |
1407 case sw_status: | |
1408 if (ch == ' ') { | |
1409 break; | |
1410 } | |
1411 | |
1412 if (ch < '0' || ch > '9') { | |
1413 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1414 } | |
1415 | |
1416 ctx->status = ctx->status * 10 + ch - '0'; | |
1417 | |
1418 if (++ctx->status_count == 3) { | |
1419 state = sw_space_after_status; | |
1420 ctx->status_start = p - 2; | |
1421 } | |
1422 | |
1423 break; | |
1424 | |
1425 /* space or end of line */ | |
1426 case sw_space_after_status: | |
1427 switch (ch) { | |
1428 case ' ': | |
1429 state = sw_status_text; | |
1430 break; | |
1431 case '.': /* IIS may send 403.1, 403.2, etc */ | |
1432 state = sw_status_text; | |
1433 break; | |
1434 case CR: | |
1435 state = sw_almost_done; | |
1436 break; | |
1437 case LF: | |
1438 goto done; | |
1439 default: | |
1440 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1441 } | |
1442 break; | |
1443 | |
1444 /* any text until end of line */ | |
1445 case sw_status_text: | |
1446 switch (ch) { | |
1447 case CR: | |
1448 state = sw_almost_done; | |
1449 | |
1450 break; | |
1451 case LF: | |
1452 goto done; | |
1453 } | |
1454 break; | |
1455 | |
1456 /* end of status line */ | |
1457 case sw_almost_done: | |
1458 ctx->status_end = p - 1; | |
1459 switch (ch) { | |
1460 case LF: | |
1461 goto done; | |
1462 default: | |
1463 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1464 } | |
1465 } | |
1466 } | |
1467 | |
1468 u->buffer.pos = p; | |
1469 r->state = state; | |
1470 | |
1471 return NGX_AGAIN; | |
1472 | |
1473 done: | |
1474 | |
1475 u->buffer.pos = p + 1; | |
1476 | |
1477 if (ctx->status_end == NULL) { | |
1478 ctx->status_end = p; | |
1479 } | |
1480 | |
1481 r->state = sw_start; | |
1482 | |
1483 return NGX_OK; | |
1484 } | 1239 } |
1485 | 1240 |
1486 | 1241 |
1487 static ngx_int_t | 1242 static ngx_int_t |
1488 ngx_http_proxy_process_header(ngx_http_request_t *r) | 1243 ngx_http_proxy_process_header(ngx_http_request_t *r) |
1564 } | 1319 } |
1565 | 1320 |
1566 h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( | 1321 h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( |
1567 ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); | 1322 ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); |
1568 | 1323 |
1569 h->key.len = sizeof("Server") - 1; | 1324 ngx_str_set(&h->key, "Server"); |
1570 h->key.data = (u_char *) "Server"; | 1325 ngx_str_null(&h->value); |
1571 h->value.len = 0; | |
1572 h->value.data = NULL; | |
1573 h->lowcase_key = (u_char *) "server"; | 1326 h->lowcase_key = (u_char *) "server"; |
1574 } | 1327 } |
1575 | 1328 |
1576 if (r->upstream->headers_in.date == NULL) { | 1329 if (r->upstream->headers_in.date == NULL) { |
1577 h = ngx_list_push(&r->upstream->headers_in.headers); | 1330 h = ngx_list_push(&r->upstream->headers_in.headers); |
1579 return NGX_ERROR; | 1332 return NGX_ERROR; |
1580 } | 1333 } |
1581 | 1334 |
1582 h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); | 1335 h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); |
1583 | 1336 |
1584 h->key.len = sizeof("Date") - 1; | 1337 ngx_str_set(&h->key, "Date"); |
1585 h->key.data = (u_char *) "Date"; | 1338 ngx_str_null(&h->value); |
1586 h->value.len = 0; | |
1587 h->value.data = NULL; | |
1588 h->lowcase_key = (u_char *) "date"; | 1339 h->lowcase_key = (u_char *) "date"; |
1589 } | 1340 } |
1590 | 1341 |
1591 return NGX_OK; | 1342 return NGX_OK; |
1592 } | 1343 } |
1778 pr->redirect.len) != 0) | 1529 pr->redirect.len) != 0) |
1779 { | 1530 { |
1780 return NGX_DECLINED; | 1531 return NGX_DECLINED; |
1781 } | 1532 } |
1782 | 1533 |
1783 len = prefix + pr->replacement.text.len + h->value.len - pr->redirect.len; | 1534 len = pr->replacement.text.len + h->value.len - pr->redirect.len; |
1784 | 1535 |
1785 data = ngx_pnalloc(r->pool, len); | 1536 data = ngx_pnalloc(r->pool, len); |
1786 if (data == NULL) { | 1537 if (data == NULL) { |
1787 return NGX_ERROR; | 1538 return NGX_ERROR; |
1788 } | 1539 } |
1789 | 1540 |
1790 p = data; | 1541 p = ngx_copy(data, h->value.data, prefix); |
1791 | |
1792 p = ngx_copy(p, h->value.data, prefix); | |
1793 | 1542 |
1794 if (pr->replacement.text.len) { | 1543 if (pr->replacement.text.len) { |
1795 p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len); | 1544 p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len); |
1796 } | 1545 } |
1797 | 1546 |
1825 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | 1574 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
1826 | 1575 |
1827 e.ip = pr->replacement.vars.lengths; | 1576 e.ip = pr->replacement.vars.lengths; |
1828 e.request = r; | 1577 e.request = r; |
1829 | 1578 |
1830 len = prefix + h->value.len - pr->redirect.len; | 1579 len = h->value.len - pr->redirect.len; |
1831 | 1580 |
1832 while (*(uintptr_t *) e.ip) { | 1581 while (*(uintptr_t *) e.ip) { |
1833 lcode = *(ngx_http_script_len_code_pt *) e.ip; | 1582 lcode = *(ngx_http_script_len_code_pt *) e.ip; |
1834 len += lcode(&e); | 1583 len += lcode(&e); |
1835 } | 1584 } |
1837 data = ngx_pnalloc(r->pool, len); | 1586 data = ngx_pnalloc(r->pool, len); |
1838 if (data == NULL) { | 1587 if (data == NULL) { |
1839 return NGX_ERROR; | 1588 return NGX_ERROR; |
1840 } | 1589 } |
1841 | 1590 |
1842 p = data; | 1591 p = ngx_copy(data, h->value.data, prefix); |
1843 | |
1844 p = ngx_copy(p, h->value.data, prefix); | |
1845 | 1592 |
1846 e.ip = pr->replacement.vars.values; | 1593 e.ip = pr->replacement.vars.values; |
1847 e.pos = p; | 1594 e.pos = p; |
1848 | 1595 |
1849 while (*(uintptr_t *) e.ip) { | 1596 while (*(uintptr_t *) e.ip) { |
1911 * conf->headers_set = NULL; | 1658 * conf->headers_set = NULL; |
1912 * conf->headers_set_hash = NULL; | 1659 * conf->headers_set_hash = NULL; |
1913 * conf->body_set_len = NULL; | 1660 * conf->body_set_len = NULL; |
1914 * conf->body_set = NULL; | 1661 * conf->body_set = NULL; |
1915 * conf->body_source = { 0, NULL }; | 1662 * conf->body_source = { 0, NULL }; |
1916 * conf->rewrite_locations = NULL; | 1663 * conf->redirects = NULL; |
1917 */ | 1664 */ |
1918 | 1665 |
1919 conf->upstream.store = NGX_CONF_UNSET; | 1666 conf->upstream.store = NGX_CONF_UNSET; |
1920 conf->upstream.store_access = NGX_CONF_UNSET_UINT; | 1667 conf->upstream.store_access = NGX_CONF_UNSET_UINT; |
1921 conf->upstream.buffering = NGX_CONF_UNSET; | 1668 conf->upstream.buffering = NGX_CONF_UNSET; |
1936 conf->upstream.pass_request_body = NGX_CONF_UNSET; | 1683 conf->upstream.pass_request_body = NGX_CONF_UNSET; |
1937 | 1684 |
1938 #if (NGX_HTTP_CACHE) | 1685 #if (NGX_HTTP_CACHE) |
1939 conf->upstream.cache = NGX_CONF_UNSET_PTR; | 1686 conf->upstream.cache = NGX_CONF_UNSET_PTR; |
1940 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT; | 1687 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT; |
1688 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR; | |
1689 conf->upstream.no_cache = NGX_CONF_UNSET_PTR; | |
1941 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; | 1690 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; |
1942 #endif | 1691 #endif |
1943 | 1692 |
1944 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; | 1693 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; |
1945 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; | 1694 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; |
1966 ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | 1715 ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
1967 { | 1716 { |
1968 ngx_http_proxy_loc_conf_t *prev = parent; | 1717 ngx_http_proxy_loc_conf_t *prev = parent; |
1969 ngx_http_proxy_loc_conf_t *conf = child; | 1718 ngx_http_proxy_loc_conf_t *conf = child; |
1970 | 1719 |
1720 u_char *p; | |
1971 size_t size; | 1721 size_t size; |
1972 ngx_str_t *h; | |
1973 ngx_keyval_t *s; | 1722 ngx_keyval_t *s; |
1974 ngx_hash_init_t hash; | 1723 ngx_hash_init_t hash; |
1724 ngx_http_core_loc_conf_t *clcf; | |
1975 ngx_http_proxy_redirect_t *pr; | 1725 ngx_http_proxy_redirect_t *pr; |
1976 ngx_http_script_compile_t sc; | 1726 ngx_http_script_compile_t sc; |
1977 | 1727 |
1978 if (conf->upstream.store != 0) { | 1728 if (conf->upstream.store != 0) { |
1979 ngx_conf_merge_value(conf->upstream.store, | 1729 ngx_conf_merge_value(conf->upstream.store, |
2160 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | 1910 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { |
2161 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | 1911 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET |
2162 |NGX_HTTP_UPSTREAM_FT_OFF; | 1912 |NGX_HTTP_UPSTREAM_FT_OFF; |
2163 } | 1913 } |
2164 | 1914 |
1915 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass, | |
1916 prev->upstream.cache_bypass, NULL); | |
1917 | |
1918 ngx_conf_merge_ptr_value(conf->upstream.no_cache, | |
1919 prev->upstream.no_cache, NULL); | |
1920 | |
1921 if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) { | |
1922 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
1923 "\"proxy_no_cache\" functionality has been changed in 0.8.46, " | |
1924 "now it should be used together with \"proxy_cache_bypass\""); | |
1925 } | |
1926 | |
2165 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | 1927 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, |
2166 prev->upstream.cache_valid, NULL); | 1928 prev->upstream.cache_valid, NULL); |
2167 | 1929 |
2168 if (conf->cache_key.value.data == NULL) { | 1930 if (conf->cache_key.value.data == NULL) { |
2169 conf->cache_key = prev->cache_key; | 1931 conf->cache_key = prev->cache_key; |
2212 if (pr == NULL) { | 1974 if (pr == NULL) { |
2213 return NGX_CONF_ERROR; | 1975 return NGX_CONF_ERROR; |
2214 } | 1976 } |
2215 | 1977 |
2216 pr->handler = ngx_http_proxy_rewrite_redirect_text; | 1978 pr->handler = ngx_http_proxy_rewrite_redirect_text; |
2217 pr->redirect = conf->url; | |
2218 | 1979 |
2219 if (conf->vars.uri.len) { | 1980 if (conf->vars.uri.len) { |
1981 pr->redirect = conf->url; | |
2220 pr->replacement.text = conf->location; | 1982 pr->replacement.text = conf->location; |
2221 | 1983 |
2222 } else { | 1984 } else { |
2223 pr->replacement.text.len = 0; | 1985 pr->redirect.len = conf->url.len + sizeof("/") - 1; |
2224 pr->replacement.text.data = NULL; | 1986 |
1987 p = ngx_pnalloc(cf->pool, pr->redirect.len); | |
1988 if (p == NULL) { | |
1989 return NGX_CONF_ERROR; | |
1990 } | |
1991 | |
1992 pr->redirect.data = p; | |
1993 | |
1994 p = ngx_cpymem(p, conf->url.data, conf->url.len); | |
1995 *p = '/'; | |
1996 | |
1997 ngx_str_set(&pr->replacement.text, "/"); | |
2225 } | 1998 } |
2226 } | 1999 } |
2227 } | |
2228 | |
2229 /* STUB */ | |
2230 if (prev->proxy_lengths) { | |
2231 conf->proxy_lengths = prev->proxy_lengths; | |
2232 conf->proxy_values = prev->proxy_values; | |
2233 } | 2000 } |
2234 | 2001 |
2235 #if (NGX_HTTP_SSL) | 2002 #if (NGX_HTTP_SSL) |
2236 if (conf->upstream.ssl == NULL) { | 2003 if (conf->upstream.ssl == NULL) { |
2237 conf->upstream.ssl = prev->upstream.ssl; | 2004 conf->upstream.ssl = prev->upstream.ssl; |
2249 | 2016 |
2250 hash.max_size = conf->headers_hash_max_size; | 2017 hash.max_size = conf->headers_hash_max_size; |
2251 hash.bucket_size = conf->headers_hash_bucket_size; | 2018 hash.bucket_size = conf->headers_hash_bucket_size; |
2252 hash.name = "proxy_headers_hash"; | 2019 hash.name = "proxy_headers_hash"; |
2253 | 2020 |
2254 #if (NGX_HTTP_CACHE) | |
2255 | |
2256 h = conf->upstream.cache ? ngx_http_proxy_hide_cache_headers: | |
2257 ngx_http_proxy_hide_headers; | |
2258 #else | |
2259 | |
2260 h = ngx_http_proxy_hide_headers; | |
2261 | |
2262 #endif | |
2263 | |
2264 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, | 2021 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, |
2265 &prev->upstream, h, &hash) | 2022 &prev->upstream, ngx_http_proxy_hide_headers, &hash) |
2266 != NGX_OK) | 2023 != NGX_OK) |
2267 { | 2024 { |
2268 return NGX_CONF_ERROR; | 2025 return NGX_CONF_ERROR; |
2269 } | 2026 } |
2270 | 2027 |
2271 if (conf->upstream.upstream == NULL) { | 2028 if (conf->upstream.upstream == NULL) { |
2272 conf->upstream.upstream = prev->upstream.upstream; | 2029 conf->upstream.upstream = prev->upstream.upstream; |
2273 conf->vars = prev->vars; | 2030 conf->vars = prev->vars; |
2274 } | 2031 } |
2275 | 2032 |
2033 if (conf->proxy_lengths == NULL) { | |
2034 conf->proxy_lengths = prev->proxy_lengths; | |
2035 conf->proxy_values = prev->proxy_values; | |
2036 } | |
2037 | |
2038 if (conf->upstream.upstream || conf->proxy_lengths) { | |
2039 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
2040 if (clcf->handler == NULL && clcf->lmt_excpt) { | |
2041 clcf->handler = ngx_http_proxy_handler; | |
2042 conf->location = prev->location; | |
2043 } | |
2044 } | |
2276 | 2045 |
2277 if (conf->body_source.data == NULL) { | 2046 if (conf->body_source.data == NULL) { |
2278 conf->body_source = prev->body_source; | 2047 conf->body_source = prev->body_source; |
2279 conf->body_set_len = prev->body_set_len; | 2048 conf->body_set_len = prev->body_set_len; |
2280 conf->body_set = prev->body_set; | 2049 conf->body_set = prev->body_set; |
2307 s = ngx_array_push(conf->headers_source); | 2076 s = ngx_array_push(conf->headers_source); |
2308 if (s == NULL) { | 2077 if (s == NULL) { |
2309 return NGX_CONF_ERROR; | 2078 return NGX_CONF_ERROR; |
2310 } | 2079 } |
2311 | 2080 |
2312 s->key.len = sizeof("Content-Length") - 1; | 2081 ngx_str_set(&s->key, "Content-Length"); |
2313 s->key.data = (u_char *) "Content-Length"; | 2082 ngx_str_set(&s->value, "$proxy_internal_body_length"); |
2314 s->value.len = sizeof("$proxy_internal_body_length") - 1; | |
2315 s->value.data = (u_char *) "$proxy_internal_body_length"; | |
2316 } | 2083 } |
2317 | 2084 |
2318 if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) { | 2085 if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) { |
2319 return NGX_CONF_ERROR; | 2086 return NGX_CONF_ERROR; |
2320 } | 2087 } |
2329 { | 2096 { |
2330 u_char *p; | 2097 u_char *p; |
2331 size_t size; | 2098 size_t size; |
2332 uintptr_t *code; | 2099 uintptr_t *code; |
2333 ngx_uint_t i; | 2100 ngx_uint_t i; |
2101 ngx_array_t headers_names; | |
2334 ngx_keyval_t *src, *s, *h; | 2102 ngx_keyval_t *src, *s, *h; |
2335 ngx_hash_key_t *hk; | 2103 ngx_hash_key_t *hk; |
2336 ngx_hash_init_t hash; | 2104 ngx_hash_init_t hash; |
2337 ngx_http_script_compile_t sc; | 2105 ngx_http_script_compile_t sc; |
2338 ngx_http_script_copy_code_t *copy; | 2106 ngx_http_script_copy_code_t *copy; |
2353 { | 2121 { |
2354 return NGX_OK; | 2122 return NGX_OK; |
2355 } | 2123 } |
2356 | 2124 |
2357 | 2125 |
2358 conf->headers_names = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t)); | 2126 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
2359 if (conf->headers_names == NULL) { | 2127 != NGX_OK) |
2128 { | |
2360 return NGX_ERROR; | 2129 return NGX_ERROR; |
2361 } | 2130 } |
2362 | 2131 |
2363 if (conf->headers_source == NULL) { | 2132 if (conf->headers_source == NULL) { |
2364 conf->headers_source = ngx_array_create(cf->pool, 4, | 2133 conf->headers_source = ngx_array_create(cf->pool, 4, |
2415 | 2184 |
2416 | 2185 |
2417 src = conf->headers_source->elts; | 2186 src = conf->headers_source->elts; |
2418 for (i = 0; i < conf->headers_source->nelts; i++) { | 2187 for (i = 0; i < conf->headers_source->nelts; i++) { |
2419 | 2188 |
2420 hk = ngx_array_push(conf->headers_names); | 2189 hk = ngx_array_push(&headers_names); |
2421 if (hk == NULL) { | 2190 if (hk == NULL) { |
2422 return NGX_ERROR; | 2191 return NGX_ERROR; |
2423 } | 2192 } |
2424 | 2193 |
2425 hk->key = src[i].key; | 2194 hk->key = src[i].key; |
2563 hash.bucket_size = conf->headers_hash_bucket_size; | 2332 hash.bucket_size = conf->headers_hash_bucket_size; |
2564 hash.name = "proxy_headers_hash"; | 2333 hash.name = "proxy_headers_hash"; |
2565 hash.pool = cf->pool; | 2334 hash.pool = cf->pool; |
2566 hash.temp_pool = NULL; | 2335 hash.temp_pool = NULL; |
2567 | 2336 |
2568 if (ngx_hash_init(&hash, conf->headers_names->elts, | 2337 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
2569 conf->headers_names->nelts) | |
2570 != NGX_OK) | |
2571 { | |
2572 return NGX_ERROR; | |
2573 } | |
2574 | |
2575 return NGX_OK; | |
2576 } | 2338 } |
2577 | 2339 |
2578 | 2340 |
2579 static char * | 2341 static char * |
2580 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2342 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2705 static char * | 2467 static char * |
2706 ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2468 ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2707 { | 2469 { |
2708 ngx_http_proxy_loc_conf_t *plcf = conf; | 2470 ngx_http_proxy_loc_conf_t *plcf = conf; |
2709 | 2471 |
2472 u_char *p; | |
2710 ngx_str_t *value; | 2473 ngx_str_t *value; |
2711 ngx_array_t *vars_lengths, *vars_values; | 2474 ngx_array_t *vars_lengths, *vars_values; |
2712 ngx_http_script_compile_t sc; | 2475 ngx_http_script_compile_t sc; |
2713 ngx_http_proxy_redirect_t *pr; | 2476 ngx_http_proxy_redirect_t *pr; |
2714 | 2477 |
2752 if (pr == NULL) { | 2515 if (pr == NULL) { |
2753 return NGX_CONF_ERROR; | 2516 return NGX_CONF_ERROR; |
2754 } | 2517 } |
2755 | 2518 |
2756 if (ngx_strcmp(value[1].data, "default") == 0) { | 2519 if (ngx_strcmp(value[1].data, "default") == 0) { |
2520 if (plcf->proxy_lengths) { | |
2521 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2522 "\"proxy_redirect default\" may not be used " | |
2523 "with \"proxy_pass\" directive with variables"); | |
2524 return NGX_CONF_ERROR; | |
2525 } | |
2526 | |
2757 if (plcf->url.data == NULL) { | 2527 if (plcf->url.data == NULL) { |
2758 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2528 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2759 "\"proxy_rewrite_location default\" must go " | 2529 "\"proxy_redirect default\" must go " |
2760 "after the \"proxy_pass\" directive"); | 2530 "after the \"proxy_pass\" directive"); |
2761 return NGX_CONF_ERROR; | 2531 return NGX_CONF_ERROR; |
2762 } | 2532 } |
2763 | 2533 |
2764 pr->handler = ngx_http_proxy_rewrite_redirect_text; | 2534 pr->handler = ngx_http_proxy_rewrite_redirect_text; |
2765 pr->redirect = plcf->url; | |
2766 | 2535 |
2767 if (plcf->vars.uri.len) { | 2536 if (plcf->vars.uri.len) { |
2537 pr->redirect = plcf->url; | |
2768 pr->replacement.text = plcf->location; | 2538 pr->replacement.text = plcf->location; |
2769 | 2539 |
2770 } else { | 2540 } else { |
2771 pr->replacement.text.len = 0; | 2541 pr->redirect.len = plcf->url.len + sizeof("/") - 1; |
2772 pr->replacement.text.data = NULL; | 2542 |
2543 p = ngx_pnalloc(cf->pool, pr->redirect.len); | |
2544 if (p == NULL) { | |
2545 return NGX_CONF_ERROR; | |
2546 } | |
2547 | |
2548 pr->redirect.data = p; | |
2549 | |
2550 p = ngx_cpymem(p, plcf->url.data, plcf->url.len); | |
2551 *p = '/'; | |
2552 | |
2553 ngx_str_set(&pr->replacement.text, "/"); | |
2773 } | 2554 } |
2774 | 2555 |
2775 return NGX_CONF_OK; | 2556 return NGX_CONF_OK; |
2776 } | 2557 } |
2777 | 2558 |
2956 | 2737 |
2957 return NGX_CONF_OK; | 2738 return NGX_CONF_OK; |
2958 } | 2739 } |
2959 | 2740 |
2960 | 2741 |
2961 static char * | |
2962 ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, | |
2963 ngx_command_t *cmd, void *conf) | |
2964 { | |
2965 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2966 "\"proxy_upstream_max_fails\" is not supported, " | |
2967 "use the \"max_fails\" parameter of the \"server\" directive ", | |
2968 "inside the \"upstream\" block"); | |
2969 | |
2970 return NGX_CONF_ERROR; | |
2971 } | |
2972 | |
2973 | |
2974 static char * | |
2975 ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
2976 ngx_command_t *cmd, void *conf) | |
2977 { | |
2978 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2979 "\"proxy_upstream_fail_timeout\" is not supported, " | |
2980 "use the \"fail_timeout\" parameter of the \"server\" directive ", | |
2981 "inside the \"upstream\" block"); | |
2982 | |
2983 return NGX_CONF_ERROR; | |
2984 } | |
2985 | |
2986 | |
2987 #if (NGX_HTTP_SSL) | 2742 #if (NGX_HTTP_SSL) |
2988 | 2743 |
2989 static ngx_int_t | 2744 static ngx_int_t |
2990 ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf) | 2745 ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf) |
2991 { | 2746 { |
3027 if (u->no_port || u->port == u->default_port) { | 2782 if (u->no_port || u->port == u->default_port) { |
3028 | 2783 |
3029 v->host_header = u->host; | 2784 v->host_header = u->host; |
3030 | 2785 |
3031 if (u->default_port == 80) { | 2786 if (u->default_port == 80) { |
3032 v->port.len = sizeof("80") - 1; | 2787 ngx_str_set(&v->port, "80"); |
3033 v->port.data = (u_char *) "80"; | |
3034 | 2788 |
3035 } else { | 2789 } else { |
3036 v->port.len = sizeof("443") - 1; | 2790 ngx_str_set(&v->port, "443"); |
3037 v->port.data = (u_char *) "443"; | |
3038 } | 2791 } |
3039 | 2792 |
3040 } else { | 2793 } else { |
3041 v->host_header.len = u->host.len + 1 + u->port_text.len; | 2794 v->host_header.len = u->host.len + 1 + u->port_text.len; |
3042 v->host_header.data = u->host.data; | 2795 v->host_header.data = u->host.data; |
3044 } | 2797 } |
3045 | 2798 |
3046 v->key_start.len += v->host_header.len; | 2799 v->key_start.len += v->host_header.len; |
3047 | 2800 |
3048 } else { | 2801 } else { |
3049 v->host_header.len = sizeof("localhost") - 1; | 2802 ngx_str_set(&v->host_header, "localhost"); |
3050 v->host_header.data = (u_char *) "localhost"; | 2803 ngx_str_null(&v->port); |
3051 v->port.len = 0; | |
3052 v->port.data = (u_char *) ""; | |
3053 v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1; | 2804 v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1; |
3054 } | 2805 } |
3055 | 2806 |
3056 v->uri = u->uri; | 2807 v->uri = u->uri; |
3057 } | 2808 } |