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

Is it possible to disable the Connect protocol? #705

Closed
JPFrancoia opened this issue Mar 10, 2024 · 2 comments
Closed

Is it possible to disable the Connect protocol? #705

JPFrancoia opened this issue Mar 10, 2024 · 2 comments

Comments

@JPFrancoia
Copy link

Hi,
First of, Connect is amazing. It fixes most of the annoying things with gRPC. It makes debugging super easy with the Connect protocol and I don't need to deploy an Envoy proxy to support grpc-web.

Hopefully this will be a quick question. I'm preparing to rollout my backend, implemented with Connect. The backend needs to support the gRPC and gRPC-web protocols (these are the protocols used by my clients). However I do not want the Connect protocol to be enabled once the backend is deployed. It's very practical for development, but once live I don't want it enabled. Is there a way to disable it?

I could write an interceptor to reject requests with the Connect-Protocol-Version header, but I was wondering if there is a better way.

Cheers

@emcfarlane
Copy link
Contributor

It's currently not an option that is supported. As a workaround for now you may inspect the content type to classify the request as a grpc/grpcWeb request and return a 415 Unsupported Media Type status otherwise. Here is an example in HTTP middleware:

func grpcOnlyMiddleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if !strings.HasPrefix(r.Header.Get("Content-Type"), "application/grpc") {
			w.WriteHeader(http.StatusUnsupportedMediaType)
			return
		}
		next.ServeHTTP(w, r)
	})
}

@JPFrancoia
Copy link
Author

Perfect, works like a charm, thank you.

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

No branches or pull requests

2 participants