Skip to content

fix(ext-plugin-post-resp): avoid H2/H3 Content-Length check when read…#13243

Open
Goend wants to merge 1 commit intoapache:masterfrom
Goend:master
Open

fix(ext-plugin-post-resp): avoid H2/H3 Content-Length check when read…#13243
Goend wants to merge 1 commit intoapache:masterfrom
Goend:master

Conversation

@Goend
Copy link
Copy Markdown

@Goend Goend commented Apr 17, 2026

Description

This PR fixes an issue in ext-plugin-post-resp when handling HTTP/2 and HTTP/3 requests without a Content-Length header.

Currently, ext-plugin-post-resp replays the original client request to upstream and reads the request body via core.request.get_body(). After the behavior introduced in #10887, core.request.get_body() rejects
HTTP/2 and HTTP/3 requests that do not contain a Content-Length header.

This causes valid body-less requests such as normal GET requests over HTTP/2 to fail unexpectedly with 502 when ext-plugin-post-resp is enabled.

This PR avoids using core.request.get_body() in ext-plugin-post-resp and reads the request body directly from the Nginx request APIs instead. As a result, body-less HTTP/2 and HTTP/3 requests are handled
correctly, while requests that actually contain a body can still be forwarded as expected.

Which issue(s) this PR fixes:

Fixes #13237

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Apr 17, 2026
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 23, 2026
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 23, 2026
Comment thread apisix/core/request.lua
end
end

-- check content-length header for http2/http3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification is too extensive, we recommend:

  1. Narrow the fix to ext-plugin-post-resp.lua: bypass core.request.get_body() and use ngx.req.read_body() + ngx.req.get_body_data() directly for the upstream replay request
  2. Or refine the check in get_body(): skip the Content-Length check for request methods that typically have no body (GET, HEAD, DELETE, OPTIONS), while keeping it for POST/PUT/PATCH
  3. Add targeted tests: add H2 test cases specifically for ext-plugin-post-resp to cover the reported scenario, and verify no regression in other H2-dependent plugins (e.g., grpc-web, batch-requests)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Baoyuantop Thanks for the review. I initially took the same approach of only bypassing the check in ext-plugin-post-resp, but after digging into the upstream lua-nginx-module, I believe removing the check from get_body() is actually the correct fix. This Content-Length validation was originally added to align with lua-nginx-module's documented limitation (see openresty/lua-nginx-module#2237). However, upstream has since relaxed this restriction: - openresty/lua-nginx-module@e0d19f7 partially lifted it - openresty/lua-nginx-module@6e29c1a further relaxed it, and the docs no longer state that ngx.req.read_body() requires Content-Length for H2/H3 Since the underlying layer no longer enforces this restriction, keeping the check in get_body() makes APISIX stricter than the runtime — it blocks valid H2/H3 requests across all 20+ plugins that call get_body(), not just ext-plugin-post-resp. Removing it here is not "too extensive" — it's removing a guard that no longer serves its purpose.
I'll add targeted H2 tests for ext-plugin-post-resp as suggested. Let me know your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: 502 error when using ext-plugin-post-resp due to HTTP/2/HTTP/3 request without Content-Length header

2 participants