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

server.ServeHTTP Experimental Status #7566

Closed
ekky-kharismadhany opened this issue Aug 27, 2024 · 10 comments
Closed

server.ServeHTTP Experimental Status #7566

ekky-kharismadhany opened this issue Aug 27, 2024 · 10 comments

Comments

@ekky-kharismadhany
Copy link

Hi

I would like to ask whether the server.ServeHTTP is still on the experimental status. It's been 7 years since the experimental status is added to codebase #1429.

Thank you for the help

@purnesh42H
Copy link
Contributor

Yes, it is marked as experimental currently. I will confirm with the team if can remove experimental status

@dfawley
Copy link
Member

dfawley commented Aug 27, 2024

There are no plans to stabilize the functionality. gRPC's HTTP/2 server provides more features than the Go HTTP server and we haven't yet heard any critical use cases that require the Go HTTP server, so it's hard to justify spending time improving it.

@purnesh42H
Copy link
Contributor

@ekky-kharismadhany do you have any specific use case that's relevant here?

@ekky-kharismadhany
Copy link
Author

Hi, sorry for the late reply

I currently working on some application that use grpc-gateway project. On those projects, my organization uses same port to serve RESTful API and gRPC.

The current implementation is using a third-party library which currently does not have any update for the last 3 years. So, I'm searching a method to handle this issue and found that server.ServeHTTP can be used to solve my organization issue.

That being said, do you have any recommendation or experience on how an application can serve both RESTful and gRPC at the same port?

Thank you

@isgj
Copy link

isgj commented Sep 1, 2024

Another way I used that API was by wrapping it with an HTTP middleware it could serve also grpc-web requests. It required h2 also for grpc-web requests, but it worked well for unary and server streaming RPCs.

There are some implementations that offer also grpc-web, it might be considered.

@ekky-kharismadhany
Copy link
Author

Hi @isgj , I also use h2c for my proof-of-concept code. It works well.

	server := grpc.NewServer(opts...)
	reflection.Register(server)
	echo_rpc.RegisterEchoServerServer(server, initServer())
	logger.Info("server started", "host", host)
	multiServer := http.Server{
		Handler: h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if r.ProtoMajor == 2 && r.Header.Get("content-type") == "application/grpc" {
				server.ServeHTTP(w, r)
			} else {
				mux.ServeHTTP(w, r)
			}
		}), &http2.Server{}),
	}
	if err := multiServer.Serve(listener); err != nil {
		panic(err.Error())
	}

@purnesh42H
Copy link
Contributor

Better approach would be to have a proxy or custom middleware for routing traffic accordingly. Alternatively, you can consider libraries like cmux to multiplex connections based on their payload

@ekky-kharismadhany
Copy link
Author

ekky-kharismadhany commented Sep 3, 2024

Hi @purnesh42H

cmux is the third-party project I referred to earlier in this issue. I'm looking for an alternative to cmux. But your approach on using proxy or a custom middleware is interesting. Could you elaborate those approaches, please?

Thank you

@purnesh42H
Copy link
Contributor

@ekky-kharismadhany you can have a custom proxy which does the routing based on if request is http/grpc. you can implement the dialing logic in your custom dialer to connect to the proxy and then forward the traffic. See here https://github.com/grpc/grpc-go/blob/master/Documentation/proxy.md

Alternatively, is it not possible for you to have just grpc service and have a gateway to do automatic transcoding of converting http request to grpc and grpc response to http?

@ekky-kharismadhany
Copy link
Author

Hi @purnesh42H

I will take a look at this https://github.com/grpc/grpc-go/blob/master/Documentation/proxy.md. Thank you

Unfortunately, my organization already use grpc-gateway to handle automatic transcoding between http request and grpc response. Thus, adding one in front of our service will adds more layer to the app.

I thank you for your help.

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

No branches or pull requests

6 participants
@purnesh42H @isgj @dfawley @ekky-kharismadhany and others