Skip to content

fix(http): send header-handler rejections before the body - #920

Open
Yundi339 wants to merge 2 commits into
ithewei:masterfrom
Yundi339:fix/header-handler-early-response
Open

Yundi339 wants to merge 2 commits into
ithewei:masterfrom
Yundi339:fix/header-handler-early-response

Conversation

@Yundi339

@Yundi339 Yundi339 commented Oct 29, 2026 •

Copy link
Copy Markdown

问题

headerHandler 在请求头解析完成后、请求体接收前执行。它返回错误状态码时,当前实现只记录错误,真正的响应要等到 onMessageComplete 才发送,因此服务器会继续读取请求体。

这样,请求头阶段已经可以确定的拒绝无法提前生效。例如鉴权失败或请求体超过限制时,服务端仍然要等客户端把声明的请求体发送完,才能返回拒绝结果。

改动

当 headerHandler 返回的状态既不是成功、HTTP_STATUS_NEXT,也不是 HTTP_STATUS_CLOSE 时,立即发送该状态并关闭连接。HTTP_STATUS_CLOSE 保持原有行为,只关闭连接,不发送响应。

这样,headerHandler 可以在收到任何请求体数据之前拒绝请求。

A header handler can reject authentication or an oversized request before any body bytes arrive. Send that status immediately instead of waiting until the request body is complete.
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.

1 participant