Skip to content

Commit

Permalink
fix(proxy-wasm) execute the whole filter chain on local responses
Browse files Browse the repository at this point in the history
Co-authored-by: Caio Ramos Casimiro <[email protected]>
  • Loading branch information
thibaultcha and casimiro committed Oct 4, 2023
1 parent 95a1fbf commit e2705a0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/common/proxy_wasm/ngx_proxy_wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ ngx_proxy_wasm_ctx_set_next_action(ngx_proxy_wasm_ctx_t *pwctx,
}


static ngx_inline void
ngx_proxy_wasm_ctx_reset_chain(ngx_proxy_wasm_ctx_t *pwctx)
{
ngx_proxy_wasm_log_error(NGX_LOG_DEBUG, pwctx->log, 0,
"resetting filter chain: pwctx->exec_index "
"%ld to 0 (pwctx: %p)",
pwctx->exec_index, pwctx);

pwctx->exec_index = 0;
}


static ngx_inline ngx_proxy_wasm_exec_t *
ngx_proxy_wasm_instance2pwexec(ngx_wavm_instance_t *instance)
{
Expand Down
1 change: 1 addition & 0 deletions src/common/proxy_wasm/ngx_proxy_wasm_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ ngx_proxy_wasm_hfuncs_send_local_response(ngx_wavm_instance_t *instance,
switch (rc) {

case NGX_OK:
ngx_proxy_wasm_ctx_reset_chain(pwexec->parent);
ngx_proxy_wasm_ctx_set_next_action(pwexec->parent,
NGX_PROXY_WASM_ACTION_DONE);
break;
Expand Down
38 changes: 37 additions & 1 deletion t/03-proxy_wasm/hfuncs/102-proxy_send_local_response.t
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,42 @@ Hello world
=== TEST 18: proxy_wasm - send_local_response() in chained filters
should run all response phases of chained filters
--- wasm_modules: hostcalls
--- config
location /t {
proxy_wasm hostcalls;
proxy_wasm hostcalls 'test=/t/send_local_response/body';
proxy_wasm hostcalls;
}
--- response_body
Hello world
--- grep_error_log eval: qr/\[hostcalls\] .*/
--- grep_error_log_out eval
qr/.*? on_request_headers, \d+ headers.*
.*? testing in "RequestHeaders".*
.*? on_request_headers, \d+ headers.*
.*? testing in "RequestHeaders".*
.*? on_response_headers, \d+ headers.*
.*? on_response_headers, \d+ headers.*
.*? on_response_headers, \d+ headers.*
.*? on_response_body, \d+ bytes, eof: true.*
.*? on_response_body, \d+ bytes, eof: true.*
.*? on_response_body, \d+ bytes, eof: true.*
.*? on_done.*
.*? on_log.*
.*? on_done.*
.*? on_log.*
.*? on_done.*
.*? on_log.*/
--- no_error_log
[error]
[crit]
[alert]
=== TEST 19: proxy_wasm - send_local_response() invoked twice in chained filters
should interrupt the current phase, preventing "response already stashed"
should still run all response phases
--- wasm_modules: hostcalls
Expand Down Expand Up @@ -449,7 +485,7 @@ qr/.*? on_request_headers, \d+ headers.*
=== TEST 19: proxy_wasm - send_local_response() in chained filters as a subrequest
=== TEST 20: proxy_wasm - send_local_response() in chained filters as a subrequest
should interrupt the current phase, preventing "response already stashed"
should still run all response phases
should not have a log phase (subrequest)
Expand Down
37 changes: 18 additions & 19 deletions t/05-others/010-connection_drop.t
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,30 @@ Filters running on the same request will have their response entrypoints invoked
--- wasm_modules: hostcalls on_phases
--- config
location /t {
proxy_wasm on_phases;
proxy_wasm hostcalls;
proxy_wasm hostcalls 'test=/t/send_local_response/body';
proxy_wasm on_phases;
proxy_wasm hostcalls;
}
--- shutdown
--- ignore_response
--- grep_error_log eval: qr/\[info\] .*? on_(response|log|done).*/
--- grep_error_log_out eval
qr/.*\["hostcalls" #1\].* on_response_headers.*
.*\["on_phases" #2\].* on_response_headers.*
.*\["on_phases" #1\].* on_response_body.*
.*\["hostcalls" #1\].* on_response_body.*
.*\["on_phases" #2\].* on_response_body.*
.*\["on_phases" #1\].* on_done.*
.*\["on_phases" #1\].* on_log.*
.*\["hostcalls" #1\].* on_done.*
.*\["hostcalls" #1\].* on_log.*
.*\["on_phases" #2\].* on_done.*
.*\["on_phases" #2\].* on_log.*/
--- no_error_log eval
[
qr/.*\["on_phases" #1\].* on_response_headers.*/,
"[error]",
"[crit]",
]
qr/\A.*?\["hostcalls" #1\].*? on_response_headers.*
.*?\["hostcalls" #2\].*? on_response_headers.*
.*?\["hostcalls" #3\].*? on_response_headers.*
.*?\["hostcalls" #1\].*? on_response_body.*
.*?\["hostcalls" #2\].*? on_response_body.*
.*?\["hostcalls" #3\].*? on_response_body.*
.*?\["hostcalls" #1\].*? on_done.*
.*?\["hostcalls" #1\].*? on_log.*
.*?\["hostcalls" #2\].*? on_done.*
.*?\["hostcalls" #2\].*? on_log.*
.*?\["hostcalls" #3\].*? on_done.*
.*?\["hostcalls" #3\].*? on_log.*\Z/
--- no_error_log
[error]
[crit]
[emerg]
Expand Down

0 comments on commit e2705a0

Please sign in to comment.