Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
headerHandler在请求头解析完成后、请求体接收前执行。它返回错误状态码时,当前实现只记录错误,真正的响应要等到onMessageComplete才发送,因此服务器会继续读取请求体。这样,请求头阶段已经可以确定的拒绝无法提前生效。例如鉴权失败或请求体超过限制时,服务端仍然要等客户端把声明的请求体发送完,才能返回拒绝结果。
改动
当
headerHandler返回的状态既不是成功、HTTP_STATUS_NEXT,也不是HTTP_STATUS_CLOSE时,立即发送该状态并关闭连接。HTTP_STATUS_CLOSE保持原有行为,只关闭连接,不发送响应。这样,
headerHandler可以在收到任何请求体数据之前拒绝请求。