Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip write body when status not allowed #20

Merged
merged 1 commit into from
May 25, 2023

Conversation

rogerogers
Copy link
Contributor

@rogerogers rogerogers commented May 20, 2023

What type of PR is this?

fix

What this PR does / why we need it (English/Chinese):

en: don't write body when status not allowed. According to the RFC definition https://www.rfc-editor.org/rfc/rfc9110.html#name-204-no-content, 204 and 304 response is terminated by the end of the header section; it cannot contain content or trailers.
zh: 状态码不允许存在body的时候不写入body。根据rfc定义,204、304还有其他几个状态码,不能设置响应body,这里跳过写入body。

Which issue(s) this PR fixes:

Fixes cloudwego/hertz#788

Signed-off-by: rogrogers <rogers@rogerogers.com>
@rogerogers rogerogers changed the title fix: don't write body when status not allowed fix: skip write body when status not allowed May 21, 2023
@kolinfluence
Copy link

@rogerogers it's not just status not modified.
possible to reference this?
https://stackoverflow.com/questions/8628725/comprehensive-list-of-http-status-codes-that-dont-include-a-response-body

also, it's "ok" to include body for custom status code. so i think it's ok to have body everywhere too.

@rogerogers
Copy link
Contributor Author

https://cs.opensource.google/go/x/net/+/master:http2/http2.go;l=304
This is just a solution for this scenario. Writing a body to a status code that does not allow a body will cause the error.

@kolinfluence
Copy link

possible to expedite this merge?

Copy link

@kolinfluence kolinfluence left a comment

Choose a reason for hiding this comment

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

looks good to me

@rogerogers
Copy link
Contributor Author

cc @wzekin

server.go Show resolved Hide resolved
Copy link

@kolinfluence kolinfluence left a comment

Choose a reason for hiding this comment

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

pls just approve else 304 just crash. worst by doing nothing

@welkeyever welkeyever merged commit 962a08a into hertz-contrib:main May 25, 2023
4 checks passed
@kolinfluence
Copy link

@rogerogers @welkeyever
pls update the release version too. thx

@rogerogers rogerogers deleted the fix/status-without-body branch May 25, 2023 08:27
@rogerogers
Copy link
Contributor Author

@rogerogers @welkeyever pls update the release version too. thx

You can use github.com/hertz-contrib/http2@962a08ada7d76a386c4b47a7d65cf75d0275c291 to perform your test. and update it when we release the new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants