Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/set query merge #628

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/common/proxy_wasm/ngx_proxy_wasm_maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,19 +507,21 @@ static ngx_int_t
ngx_proxy_wasm_maps_set_path(ngx_wavm_instance_t *instance, ngx_str_t *value,
ngx_proxy_wasm_map_type_e map_type)
{
size_t len = value->len;
u_char *query;
ngx_proxy_wasm_exec_t *pwexec = ngx_proxy_wasm_instance2pwexec(instance);
ngx_proxy_wasm_ctx_t *pwctx = pwexec->parent;
ngx_http_wasm_req_ctx_t *rctx = ngx_http_proxy_wasm_get_rctx(instance);
ngx_http_request_t *r = rctx->r;

if (ngx_strchr(value->data, '?')) {
ngx_wavm_instance_trap_printf(instance,
"NYI - cannot set request path "
"with querystring");
return NGX_ERROR;
query = (u_char *) ngx_strchr(value->data, '?');
if (query) {
len = query - value->data;
r->args.len = value->len - len - 1;
r->args.data = query + 1;
}

r->uri.len = value->len;
r->uri.len = len;
r->uri.data = value->data;

if (pwctx->path.len) {
Expand Down
10 changes: 5 additions & 5 deletions src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ ngx_http_proxy_wasm_dispatch(ngx_proxy_wasm_exec_t *pwexec,
call->method.data = elt->value.data;

} else if (ngx_str_eq(elt->key.data, elt->key.len, ":path", -1)) {
call->uri.len = elt->value.len;
call->uri.data = elt->value.data;
call->path.len = elt->value.len;
call->path.data = elt->value.data;

} else if (ngx_str_eq(elt->key.data, elt->key.len,
":authority", -1))
Expand Down Expand Up @@ -330,7 +330,7 @@ ngx_http_proxy_wasm_dispatch(ngx_proxy_wasm_exec_t *pwexec,
call->error = NGX_HTTP_PROXY_WASM_DISPATCH_ERR_BAD_METHOD;
goto error;

} else if (!call->uri.len) {
} else if (!call->path.len) {
call->error = NGX_HTTP_PROXY_WASM_DISPATCH_ERR_BAD_PATH;
goto error;
}
Expand Down Expand Up @@ -577,7 +577,7 @@ ngx_http_proxy_wasm_dispatch_request(ngx_http_proxy_wasm_dispatch_t *call)
* Connection:
* Content-Length:
*/
len += call->method.len + 1 + call->uri.len + 1
len += call->method.len + 1 + call->path.len + 1
+ sizeof(ngx_http_header_version11) - 1;

len += sizeof(ngx_http_host_header) - 1 + sizeof(": ") - 1
Expand Down Expand Up @@ -638,7 +638,7 @@ ngx_http_proxy_wasm_dispatch_request(ngx_http_proxy_wasm_dispatch_t *call)
b->last = ngx_cpymem(b->last, call->method.data, call->method.len);
*b->last++ = ' ';

b->last = ngx_cpymem(b->last, call->uri.data, call->uri.len);
b->last = ngx_cpymem(b->last, call->path.data, call->path.len);
*b->last++ = ' ';

b->last = ngx_cpymem(b->last, ngx_http_header_version11,
Expand Down
2 changes: 1 addition & 1 deletion src/http/proxy_wasm/ngx_http_proxy_wasm_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct ngx_http_proxy_wasm_dispatch_s {

ngx_str_t host;
ngx_str_t method;
ngx_str_t uri;
ngx_str_t path; /* ":path" (including query) */
ngx_str_t authority;
ngx_array_t headers;
ngx_array_t trailers;
Expand Down
218 changes: 198 additions & 20 deletions t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run_tests();

__DATA__

=== TEST 1: proxy_wasm - set_http_request_header() sets a new non-builtin header
=== TEST 1: proxy_wasm - set_http_request_header() set a new non-builtin header
--- valgrind
--- wasm_modules: hostcalls
--- config
Expand All @@ -32,7 +32,7 @@ qr/.*? on_request_headers, 2 headers.*



=== TEST 2: proxy_wasm - set_http_request_header() sets a new non-builtin header (case-sensitive)
=== TEST 2: proxy_wasm - set_http_request_header() set a new non-builtin header (case-sensitive)
--- wasm_modules: hostcalls
--- config
location /t {
Expand All @@ -54,7 +54,7 @@ qr/.*? on_request_headers, 2 headers.*



=== TEST 3: proxy_wasm - set_http_request_header() sets a non-builtin headers when many headers exist
=== TEST 3: proxy_wasm - set_http_request_header() set a non-builtin headers when many headers exist
--- valgrind
--- wasm_modules: hostcalls
--- config
Expand Down Expand Up @@ -97,7 +97,7 @@ Connection: close



=== TEST 5: proxy_wasm - set_http_request_header() sets the same non-builtin header multiple times
=== TEST 5: proxy_wasm - set_http_request_header() set the same non-builtin header multiple times
--- wasm_modules: hostcalls
--- config
location /t {
Expand Down Expand Up @@ -127,7 +127,7 @@ qr/.*? on_request_headers, 3 headers.*



=== TEST 6: proxy_wasm - set_http_request_header() sets Connection header (close) when many headers exist
=== TEST 6: proxy_wasm - set_http_request_header() set Connection header (close) when many headers exist
--- wasm_modules: hostcalls
--- config
location /t {
Expand Down Expand Up @@ -158,7 +158,7 @@ qr/.*? on_request_headers, 22 headers.*



=== TEST 7: proxy_wasm - set_http_request_header() sets Connection header (keep-alive)
=== TEST 7: proxy_wasm - set_http_request_header() set Connection header (keep-alive)
--- timeout_expected: 5
--- abort
--- wasm_modules: hostcalls
Expand Down Expand Up @@ -186,7 +186,7 @@ qr/.*? on_request_headers, 2 headers.*



=== TEST 8: proxy_wasm - set_http_request_header() sets Connection header (closed)
=== TEST 8: proxy_wasm - set_http_request_header() set Connection header (closed)
--- wasm_modules: hostcalls
--- config
location /t {
Expand All @@ -210,7 +210,7 @@ qr/.*? on_request_headers, 2 headers.*



=== TEST 9: proxy_wasm - set_http_request_header() sets Content-Length header
=== TEST 9: proxy_wasm - set_http_request_header() set Content-Length header
--- wasm_modules: hostcalls
--- config
location /t {
Expand Down Expand Up @@ -263,7 +263,7 @@ qr/.*? on_request_headers, 3 headers.*



=== TEST 11: proxy_wasm - set_http_request_header() sets ':path'
=== TEST 11: proxy_wasm - set_http_request_header() set ':path'
--- wasm_modules: hostcalls
--- http_config eval
qq{
Expand Down Expand Up @@ -295,26 +295,204 @@ path: /test



=== TEST 12: proxy_wasm - set_http_request_headers() cannot set ':path' with querystring (NYI)
=== TEST 12: proxy_wasm - set_http_request_headers() set ':path' with querystring
--- wasm_modules: hostcalls
--- http_config eval
qq{
upstream test_upstream {
server unix:$ENV{TEST_NGINX_UNIX_SOCKET};
}

server {
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location / {
return 200 '\$request_uri \$uri \$is_args \$args\n';
}
}
}
--- config
location /t {
proxy_wasm hostcalls 'test=/t/set_request_header name=:path value=/test?foo=bar';
return 200;
proxy_wasm hostcalls 'test=/t/log/request_path';
proxy_pass http://test_upstream$uri$is_args$args;
}
--- error_code: 500
--- response_body_like: 500 Internal Server Error
--- grep_error_log eval: qr/(NYI|\[.*?failed resuming).*/
--- grep_error_log_out eval
qr/.*?NYI - cannot set request path with querystring.*
\[info\] .*? filter chain failed resuming: previous error \(instance trapped\)/
--- response_body
/test?foo=bar /test ? foo=bar
--- error_log
path: /test?foo=bar
--- no_error_log
[error]
[crit]



=== TEST 13: proxy_wasm - set_http_request_headers() set ':path' with empty querystring drops the querystring
--- wasm_modules: hostcalls
--- http_config eval
qq{
upstream test_upstream {
server unix:$ENV{TEST_NGINX_UNIX_SOCKET};
}

server {
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location / {
return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n';
}
}
}
--- config
location /t {
proxy_wasm hostcalls 'test=/t/set_request_header name=:path value=/test?';
proxy_wasm hostcalls 'test=/t/log/request_path';
proxy_pass http://test_upstream$uri$is_args$args;
}
--- request
GET /t?foo=bar
--- response_body
(/test) (/test) () ()
--- error_log
path: /test
--- no_error_log
[error]
[crit]



=== TEST 14: proxy_wasm - set_http_request_headers() set ':path' with empty path
--- wasm_modules: hostcalls
--- http_config eval
qq{
upstream test_upstream {
server unix:$ENV{TEST_NGINX_UNIX_SOCKET};
}

server {
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location / {
return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n';
}
}
}
--- config
location /t {
proxy_wasm hostcalls 'test=/t/set_request_header name=:path value=';
proxy_wasm hostcalls 'test=/t/log/request_path';
proxy_pass http://test_upstream$uri$is_args$args;
}
--- response_body
(/t) (/t) () ()
--- error_log
path:
--- no_error_log
[error]
[crit]



=== TEST 15: proxy_wasm - set_http_request_headers() set ':path' with single '?' has same behavior as empty path
--- wasm_modules: hostcalls
--- http_config eval
qq{
upstream test_upstream {
server unix:$ENV{TEST_NGINX_UNIX_SOCKET};
}

server {
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location / {
return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n';
}
}
}
--- config
location /t {
proxy_wasm hostcalls 'test=/t/set_request_header name=:path value=?';
proxy_wasm hostcalls 'test=/t/log/request_path';
proxy_pass http://test_upstream$uri$is_args$args;
}
--- response_body
(/t) (/t) () ()
--- error_log
path:
--- no_error_log
[error]
[crit]



=== TEST 16: proxy_wasm - set_http_request_headers() set ':path' with invalid characters (non percent-encoded)
Match the Nginx behavior (see following test).
--- wasm_modules: hostcalls
--- http_config eval
qq{
upstream test_upstream {
server unix:$ENV{TEST_NGINX_UNIX_SOCKET};
}

server {
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location / {
return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n';
}
}
}
--- config
location /set_by_proxy_wasm {
proxy_wasm hostcalls 'test=/t/set_request_header name=:path value=/test?foo=bár%20bla';
proxy_wasm hostcalls 'test=/t/log/request_path';
proxy_pass http://test_upstream$uri$is_args$args;
}
--- request
GET /set_by_proxy_wasm
--- response_body
(/test?foo=bár%20bla) (/test) (?) (foo=bár%20bla)
--- error_log
path: /test
--- no_error_log
[error]
[crit]



=== TEST 17: Nginx - proxy a querystring with invalid characters (non percent-encoded)
This test is here just as documentation. It showcases the same behavior as
set_http_request_headers(':path'); see previous test.
--- http_config eval
qq{
upstream test_upstream {
server unix:$ENV{TEST_NGINX_UNIX_SOCKET};
}

server {
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location / {
return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n';
}
}
}
--- config
location /raw_nginx {
proxy_pass http://test_upstream$uri$is_args$args;
}
--- request
GET /raw_nginx?foo=bár%20bla
--- response_body
(/raw_nginx?foo=bár%20bla) (/raw_nginx) (?) (foo=bár%20bla)
--- no_error_log
[error]
[crit]
[alert]
[stderr]



=== TEST 13: proxy_wasm - set_http_request_header() sets ':method'
=== TEST 18: proxy_wasm - set_http_request_header() set ':method'
--- wasm_modules: hostcalls
--- http_config eval
qq{
Expand Down Expand Up @@ -344,7 +522,7 @@ POST



=== TEST 14: proxy_wasm - set_http_request_header() cannot set ':scheme'
=== TEST 19: proxy_wasm - set_http_request_header() cannot set ':scheme'
--- wasm_modules: hostcalls
--- http_config eval
qq{
Expand Down
Loading
Loading