Skip to content

Instantly share code, notes, and snippets.

@nleiva
Last active July 18, 2019 16:12
Show Gist options
  • Save nleiva/afb6264fea980176305c3026217c58b4 to your computer and use it in GitHub Desktop.
Save nleiva/afb6264fea980176305c3026217c58b4 to your computer and use it in GitHub Desktop.
func grpcHandlerFunc(g *grpc.Server, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ct := r.Header.Get("Content-Type")
if r.ProtoMajor == 2 && strings.Contains(ct, "application/grpc") {
g.ServeHTTP(w, r)
} else {
h.ServeHTTP(w, r)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment