Skip to content

chore(apigw): add abort_with_json as an util, allow config httpx client limits#116037

Merged
gi0baro merged 1 commit into
masterfrom
gi0baro/apigw-enh1
May 21, 2026
Merged

chore(apigw): add abort_with_json as an util, allow config httpx client limits#116037
gi0baro merged 1 commit into
masterfrom
gi0baro/apigw-enh1

Conversation

@gi0baro
Copy link
Copy Markdown
Member

@gi0baro gi0baro commented May 21, 2026

SSIA

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 21, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cc40b70. Configure here.

Comment thread src/apigw/config.py Outdated
@gi0baro gi0baro force-pushed the gi0baro/apigw-enh1 branch from cc40b70 to e76a5dc Compare May 21, 2026 18:05
@gi0baro gi0baro force-pushed the gi0baro/apigw-enh1 branch from e76a5dc to 3511e1b Compare May 21, 2026 18:09
@gi0baro gi0baro enabled auto-merge (squash) May 21, 2026 18:15
Comment thread src/apigw/utils.py
Comment on lines +10 to +13
def abort_with_json(status: int, json_data: Any) -> None:
response.status = status
response.content_type = "application/json"
raise HTTPBytesResponse(status, body=json(json_data), headers=response.headers)
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.

Bug: The abort_with_json function may not set the Content-Type header correctly on error responses because response.content_type might not update response.headers immediately.
Severity: MEDIUM

Suggested Fix

Instead of assigning to response.content_type, directly set the header in the response.headers dictionary before raising the exception, for example: response.headers["Content-Type"] = "application/json".

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/apigw/utils.py#L10-L13

Potential issue: In the `abort_with_json` function, setting `response.content_type =
"application/json"` may not synchronously update the `response.headers` dictionary. The
function then immediately raises an `HTTPBytesResponse` using the potentially outdated
`response.headers`. This can result in an error response being sent with a JSON body but
without the corresponding `Content-Type: application/json` header, which could cause
clients to fail to parse the error message correctly.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member

@mwarkentin mwarkentin left a comment

Choose a reason for hiding this comment

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

LGTM

@gi0baro gi0baro merged commit d030206 into master May 21, 2026
61 checks passed
@gi0baro gi0baro deleted the gi0baro/apigw-enh1 branch May 21, 2026 18:33
natemoo-re pushed a commit that referenced this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants