Skip to content

Commit

Permalink
add raw_uri variable assignment in subrequest
Browse files Browse the repository at this point in the history
  • Loading branch information
flygoast committed Sep 26, 2013
1 parent 9160cbc commit 730e646
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/http/modules/lua/ngx_http_lua_subrequest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ ngx_http_lua_subrequest(ngx_http_request_t *r,
sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;

sr->raw_uri = r->raw_uri;
sr->unparsed_uri = r->unparsed_uri;
sr->method_name = ngx_http_core_get_method;
sr->http_protocol = r->http_protocol;
Expand Down
1 change: 1 addition & 0 deletions src/http/ngx_http_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,7 @@ ngx_http_subrequest(ngx_http_request_t *r,
sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;

sr->raw_uri = r->raw_uri;
sr->unparsed_uri = r->unparsed_uri;
sr->method_name = ngx_http_core_get_method;
sr->http_protocol = r->http_protocol;
Expand Down
3 changes: 1 addition & 2 deletions src/http/ngx_http_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
offsetof(ngx_http_request_t, unparsed_uri), 0, 0 },

{ ngx_string("raw_uri"), NULL, ngx_http_variable_request,
offsetof(ngx_http_request_t, raw_uri),
NGX_HTTP_VAR_NOCACHEABLE, 0 },
offsetof(ngx_http_request_t, raw_uri), 0, 0 },

{ ngx_string("uri"), NULL, ngx_http_variable_request,
offsetof(ngx_http_request_t, uri),
Expand Down
38 changes: 37 additions & 1 deletion tests/nginx-tests/nginx-tests/http_raw_uri_variable.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Test::Nginx;
select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(6)
my $t = Test::Nginx->new()->has(qw/http rewrite addition/)->plan(18)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
Expand All @@ -43,6 +43,26 @@ http {
add_header X-RAW-URI $raw_uri;
return 200;
}
location /sr {
types { }
default_type text/html;
add_before_body /addition;
return 200;
}
location /addition {
return 200 "X-RAW-URI: $raw_uri\r\n";
}
location /lua {
default_type 'text/html';
content_by_lua '
local res = ngx.location.capture("/addition");
ngx.print(res.body);
';
}
}
}
Expand All @@ -59,6 +79,22 @@ raw_uri('/rawuri?arg=%2F', '/rawuri', 'uri with escaped arguments');
raw_uri('/rawuri%3F?arg=foo', '/rawuri%3F', 'escaped uri with arguments');
raw_uri('/rawuri%3F?arg=%2F', '/rawuri%3F',
'escaped uri with escaped arguments');
raw_uri('/sr', '/sr', 'uri in subrequest');
raw_uri('/sr%3F', '/sr%3F', 'escaped uri in subrequest');
raw_uri('/sr?arg=foo', '/sr', 'uri with arguments in subrequest');
raw_uri('/sr?arg=%2F', '/sr', 'uri with escaped arguments in subrequest');
raw_uri('/sr%3F?arg=foo', '/sr%3F',
'escaped uri with arguments in subrequest');
raw_uri('/sr%3F?arg=%2F', '/sr%3F',
'escaped uri with escaped arguments in subrequest');
raw_uri('/lua', '/lua', 'uri in lua subrequest');
raw_uri('/lua%3F', '/lua%3F', 'escaped uri in lua subrequest');
raw_uri('/lua?arg=foo', '/lua', 'uri with arguments in lua subrequest');
raw_uri('/lua?arg=%2F', '/lua', 'uri with escaped arguments in lua subrequest');
raw_uri('/lua%3F?arg=foo', '/lua%3F',
'escaped uri with arguments in lua subrequest');
raw_uri('/lua%3F?arg=%2F', '/lua%3F',
'escaped uri with escaped arguments in lua subrequest');

###############################################################################

Expand Down

0 comments on commit 730e646

Please sign in to comment.