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

ResponseEncode should not write any data when it encode nil #1946

Closed
Donglong opened this issue Apr 24, 2022 · 0 comments · Fixed by #1945
Closed

ResponseEncode should not write any data when it encode nil #1946

Donglong opened this issue Apr 24, 2022 · 0 comments · Fixed by #1945
Labels
bug Something isn't working

Comments

@Donglong
Copy link
Contributor

What happened:

When I don't need to return data to client

  1. When using the following code, the DefaultResponseEncode will report an error(http: request method or response status code does not allow body)
func Handle(ctx http.Context) error {
    return ctx.Result(204, nil)
}
  1. but, when using the following code, will return null string to client
func Handle(ctx http.Context) error {
    return ctx.Result(200, nil)
}

What you expected to happen:

when call ctx.Result(xxx, nil), server don't return any data to client

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Kratos version (use kratos -v): kratos version v2.2.1
  • Go version (use go version):
  • OS (e.g: cat /etc/os-release):
  • Others:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant