Skip to content

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

Open
sihyeonn wants to merge 2 commits intoapache:masterfrom
sihyeonn:fix/ai-request-rewrite-empty-body
Open

fix(ai-request-rewrite): return 400 when request body is missing#13097
sihyeonn wants to merge 2 commits intoapache: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?

Copy link
Copy Markdown
Contributor

@Baoyuantop Baoyuantop left a comment

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 <sihyeon.jang@navercorp.com>
… 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 <sihyeon.jang@navercorp.com>
@sihyeonn sihyeonn force-pushed the fix/ai-request-rewrite-empty-body branch from e5692d3 to be76e63 Compare April 9, 2026 21:42
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.

2 participants