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

Streaming proto can not generate http code #1958

Closed
hoslo opened this issue Apr 27, 2022 · 7 comments
Closed

Streaming proto can not generate http code #1958

hoslo opened this issue Apr 27, 2022 · 7 comments
Labels

Comments

@hoslo
Copy link
Contributor

hoslo commented Apr 27, 2022

What happened:

Streaming proto can not generate http code

What you expected to happen:

generate http code

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

rpc CreateZip (CreateZipRequest) returns (stream CreateZipReply) {
option (google.api.http) = {
post: "/api/util/other/zip",
body: "*"
};
}

Anything else we need to know?:

Environment:

  • Kratos version (use kratos -v): v2.2.0
  • Go version (use go version): go version go1.18 windows/amd64
  • OS (e.g: cat /etc/os-release): centos7
  • Others:
@hoslo hoslo added the bug Something isn't working label Apr 27, 2022
@shenqidebaozi
Copy link
Sponsor Member

HTTP definitions cannot be used in streaming

@hoslo
Copy link
Contributor Author

hoslo commented Apr 27, 2022

HTTP definitions cannot be used in streaming

So how to use http streaming in kratos?

@shenqidebaozi
Copy link
Sponsor Member

Not for the time being

@hoslo
Copy link
Contributor Author

hoslo commented Apr 28, 2022

Not for the time being

How to use middleware for this custom HTTP interface?

opts := []http.ServerOption{
		http.Middleware(
			ratelimit.Server(),
			middleware.Recovery(logger),
			tracing.Server(),
			middleware.Server(logger),
			validate.Validator(),
		),
	}
srv := http.NewServer(opts...)
srv.Route("/").POST("/api/util/other/zip", func(ctx http.Context) error {
		var req v1.CreateZipRequest
		if err := ctx.Bind(&req); err != nil {
			return err
		}
		err := us.uc.CreateZipHttp(context.Background(), &req, ctx.Response())
		if err != nil {
			return err
		}
		return nil
	})

and i use ctx.Response() as streaming io.Writer get this error:
http: superfluous response.WriteHeader call from github.com/go-kratos/kratos/v2/transport/http.DefaultErrorEncoder (codec.go:68)

@shenqidebaozi
Copy link
Sponsor Member

You can refer to the usage in the xxxx.http.pb.go file generated by the tool

@tom-lch
Copy link

tom-lch commented May 6, 2022

me too,kratos can‘t’ generate stream code in xxx_http.pb.go, 什么时候可以支持kratos生成stream的http客户端呢?

@shenqidebaozi shenqidebaozi added feature and removed bug Something isn't working labels May 16, 2022
Copy link

dosubot bot commented Nov 2, 2023

Hi, @hoslo! I'm Dosu, and I'm helping the kratos team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you were experiencing an issue with the streaming proto not generating the expected HTTP code in Kratos version 2.2.0. It was mentioned that HTTP definitions cannot be used in streaming, and you asked how to use middleware for a custom HTTP interface. Another user suggested referring to the usage in the xxxx.http.pb.go file generated by the tool.

Based on the resolution, it seems that the issue has been resolved. You were informed that HTTP definitions cannot be used in streaming in Kratos, and you were advised to refer to the usage in the xxxx.http.pb.go file generated by the tool for guidance on using middleware for a custom HTTP interface.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the kratos repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the kratos repository!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 2, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants