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(proxy-wasm) implement response body buffering #381

Merged
merged 3 commits into from
Dec 2, 2023

Conversation

thibaultcha
Copy link
Member

@thibaultcha thibaultcha commented Aug 10, 2023

First this fixes on_response_body execution of requests when they issue subrequests that produce a body (see 004-on_http_phases.t). This unlocks testing of response body buffering via subrequests producing chunked responses (ngx_chain_t buffers).

Response body buffering itself is implemented as part of ngx_http_wasm_filter_module, so as to be usable from other components than just proxy-wasm. Response body buffering is enabled via rctx->resp_buffering which is enabled when ngx_wasm_ops_resume returns NGX_AGAIN, which for filters translates to returning PAUSE from on_http_response_body.

If and when the response body buffers are full, then the next on_http_response_body call will have eof=false, and more invocations can be expected, as the body must be proxied in chunks.

If the response body fits in the buffers, then the next on_http_response_body call will have eof=true as one would expect.

We catch "response body buffering already requested" in ngx_proxy_wasm to produce a proxy-wasm error message, as this feature is currently only exposed through it.


  • buffer reuse
  • gzip tests - out of scope (dev env binary work)
  • CI & Valgrind
  • coverage
  • documentation
  • changelog - out of scope

@thibaultcha thibaultcha added the pr/work-in-progress PR: Work in progress label Aug 10, 2023
@thibaultcha thibaultcha force-pushed the feat/response-body-buffering branch 4 times, most recently from 73885b8 to 73317c7 Compare August 11, 2023 05:24
@coveralls
Copy link

coveralls commented Aug 11, 2023

Pull Request Test Coverage Report for Build 5985850296

  • 119 of 125 (95.2%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 91.181%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/http/ngx_http_wasm_filter_module.c 107 113 94.69%
Totals Coverage Status
Change from base Build 5985845284: 0.05%
Covered Lines: 7703
Relevant Lines: 8448

💛 - Coveralls

@thibaultcha thibaultcha removed the pr/work-in-progress PR: Work in progress label Aug 25, 2023
@thibaultcha thibaultcha force-pushed the feat/response-body-buffering branch 7 times, most recently from d5d6767 to f3e45e7 Compare August 26, 2023 16:30
@thibaultcha thibaultcha added the pr/on-hold PR: Do not merge/close label Oct 5, 2023
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Merging #381 (2f0486c) into main (3d61ca1) will increase coverage by 0.05781%.
The diff coverage is 94.96403%.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##                main        #381         +/-   ##
===================================================
+ Coverage   90.06765%   90.12546%   +0.05781%     
===================================================
  Files             46          46                 
  Lines           9756        9884        +128     
===================================================
+ Hits            8787        8908        +121     
- Misses           969         976          +7     
Files Coverage Δ
src/common/proxy_wasm/ngx_proxy_wasm.c 93.30200% <100.00000%> (+0.03163%) ⬆️
src/http/ngx_http_wasm_module.c 96.02804% <100.00000%> (+0.01865%) ⬆️
src/http/proxy_wasm/ngx_http_proxy_wasm.c 93.65079% <100.00000%> (+0.10240%) ⬆️
src/wasm/ngx_wasm.h 100.00000% <ø> (ø)
src/wasm/ngx_wasm_ops.c 92.27273% <100.00000%> (+0.03528%) ⬆️
src/wasm/ngx_wasm_util.c 92.34043% <100.00000%> (+0.06574%) ⬆️
src/http/ngx_http_wasm_filter_module.c 93.82022% <94.48819%> (+0.27183%) ⬆️

@thibaultcha thibaultcha force-pushed the feat/response-body-buffering branch 2 times, most recently from 7946f70 to 371c932 Compare November 30, 2023 22:47
@thibaultcha thibaultcha removed the pr/on-hold PR: Do not merge/close label Dec 1, 2023
@thibaultcha thibaultcha force-pushed the feat/response-body-buffering branch 3 times, most recently from 396a1ca to 2da4081 Compare December 1, 2023 17:25
@thibaultcha thibaultcha force-pushed the feat/response-body-buffering branch 4 times, most recently from 6a5ec16 to bd5342b Compare December 2, 2023 03:15
This is a fix for CI, in which the SDK directories may exist but the
examples are not built and/or copied to `t/`. In any case, better making
the scripts idempotent than not invoking them at all and risking an
inconsistent state.
First, this commit fixes `on_response_body` execution of requests when
they issue subrequests that produce a body (see 004-on_http_phases.t).
This unlocks testing of response body buffering via subrequests
producing chunked responses (`ngx_chain_t` buffers).

Response body buffering itself is implemented as part of
ngx_http_wasm_filter_module, so as to be usable from other components
than just proxy-wasm. Response body buffering is enabled via
`rctx->resp_buffering` which is enabled when `ngx_wasm_ops_resume`
returns `NGX_AGAIN`, which for filters translates to returning `PAUSE`
from `on_http_response_body`.

If and when the response body buffers are full, then the next
`on_http_response_body` call will have `eof=false`, and more invocations
can be expected, as the body *must* be proxied in chunks.

If the response body fit in the buffers, then the next
`on_http_response_body` call will have `eof=true` as one would expected.

We catch "response body already requested" in ngx_proxy_wasm to produce
a proxy-wasm error message, as this feature is currently only exposed
through it.
@thibaultcha thibaultcha merged commit 4f47e96 into main Dec 2, 2023
34 checks passed
@thibaultcha thibaultcha deleted the feat/response-body-buffering branch December 2, 2023 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants