comparison src/http/modules/ngx_http_proxy_module.c @ 4377:726a1ca9b52b

Proxy: made proxy_pass with variables more consistent. If proxy_pass was used with variables and there was no URI component, nginx always used unparsed URI. This isn't consistent with "no variables" case, where e.g. rewrites are applied even if there is no URI component. Fix is to use the same logic in both cases, i.e. only use unparsed URI if it's valid and request is the main one.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 23 Dec 2011 16:04:09 +0000
parents 99437094e86f
children 70ba81827472
comparison
equal deleted inserted replaced
4376:9346356e433d 4377:726a1ca9b52b
734 ngx_memcpy(p, url.uri.data, url.uri.len); 734 ngx_memcpy(p, url.uri.data, url.uri.len);
735 735
736 url.uri.len++; 736 url.uri.len++;
737 url.uri.data = p - 1; 737 url.uri.data = p - 1;
738 } 738 }
739
740 } else {
741 url.uri = r->unparsed_uri;
742 } 739 }
743 740
744 ctx->vars.key_start = u->schema; 741 ctx->vars.key_start = u->schema;
745 742
746 ngx_http_proxy_set_vars(&url, &ctx->vars); 743 ngx_http_proxy_set_vars(&url, &ctx->vars);
804 key = ngx_array_push(&r->cache->keys); 801 key = ngx_array_push(&r->cache->keys);
805 if (key == NULL) { 802 if (key == NULL) {
806 return NGX_ERROR; 803 return NGX_ERROR;
807 } 804 }
808 805
809 if (plcf->proxy_lengths) { 806 if (plcf->proxy_lengths && ctx->vars.uri.len) {
810 807
811 *key = ctx->vars.uri; 808 *key = ctx->vars.uri;
812 u->uri = ctx->vars.uri; 809 u->uri = ctx->vars.uri;
813 810
814 return NGX_OK; 811 return NGX_OK;
914 911
915 escape = 0; 912 escape = 0;
916 loc_len = 0; 913 loc_len = 0;
917 unparsed_uri = 0; 914 unparsed_uri = 0;
918 915
919 if (plcf->proxy_lengths) { 916 if (plcf->proxy_lengths && ctx->vars.uri.len) {
920 uri_len = ctx->vars.uri.len; 917 uri_len = ctx->vars.uri.len;
921 918
922 } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main) 919 } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main)
923 { 920 {
924 unparsed_uri = 1; 921 unparsed_uri = 1;
1020 1017
1021 b->last = ngx_copy(b->last, method.data, method.len); 1018 b->last = ngx_copy(b->last, method.data, method.len);
1022 1019
1023 u->uri.data = b->last; 1020 u->uri.data = b->last;
1024 1021
1025 if (plcf->proxy_lengths) { 1022 if (plcf->proxy_lengths && ctx->vars.uri.len) {
1026 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); 1023 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len);
1027 1024
1028 } else if (unparsed_uri) { 1025 } else if (unparsed_uri) {
1029 b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len); 1026 b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len);
1030 1027