Skip to content

fix(ai-request-rewrite): return 400 when request body is missing#13097

Merged
shreemaan-abhishek merged 2 commits into
apache:masterfrom
sihyeonn:fix/ai-request-rewrite-empty-body
Apr 15, 2026
Merged

fix(ai-request-rewrite): return 400 when request body is missing#13097
shreemaan-abhishek merged 2 commits into
apache:masterfrom
sihyeonn:fix/ai-request-rewrite-empty-body

Conversation

@sihyeonn

Copy link
Copy Markdown
Contributor

Description

In the access handler of ai-request-rewrite, when core.request.get_body() returns nil without an error (i.e., the body is simply empty), the function returns without a status code. This causes the request to continue through the pipeline, where downstream code expects client_request_body to be present and fails with confusing errors.

The fix returns HTTP_BAD_REQUEST (400) to reject the request early, which is consistent with the error handling path directly above it (lines 190-193).

Before

if not client_request_body then
    core.log.warn("missing request body")
    return
end

After

if not client_request_body then
    core.log.warn("missing request body")
    return HTTP_BAD_REQUEST
end

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Mar 18, 2026
@Baoyuantop

Copy link
Copy Markdown
Contributor

This part comes from #12036. @LiteSun Can you confirm this?

@Baoyuantop Baoyuantop left a comment

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.

Please add a test for this change.

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @sihyeonn, there are some errors in the tests that aren't related to the PR. Could you merge the main branch?

When the request body is nil (not an error, just empty), the access
handler returns without a status code, which means the request
continues through the pipeline. Downstream code then attempts to use
the body, leading to unexpected errors.

Return HTTP_BAD_REQUEST (400) to reject the request early, consistent
with the error path just above it.

Signed-off-by: Sihyeon Jang <[email protected]>
… missing

Update TEST 4 to assert HTTP 400 instead of 200 when request body is
absent, reflecting the fix that returns HTTP_BAD_REQUEST for missing body.

Signed-off-by: Sihyeon Jang <[email protected]>
@sihyeonn
sihyeonn force-pushed the fix/ai-request-rewrite-empty-body branch from e5692d3 to be76e63 Compare April 9, 2026 21:42
@shreemaan-abhishek
shreemaan-abhishek merged commit 474894e into apache:master Apr 15, 2026
24 of 27 checks passed
@sihyeonn
sihyeonn deleted the fix/ai-request-rewrite-empty-body branch April 16, 2026 22:51
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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants