1 Star 1 Fork 0

Allen / go-scaffold

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
wrapper.go 593 Bytes
Copy Edit Raw Blame History
Allen authored 2020-08-24 16:17 . update to h2c
package server
import (
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"net/http"
"strings"
"google.golang.org/grpc"
)
const keyContentType = "Content-Type"
const keyGrpcHeader = "application/grpc"
// GRPCHandlerFunc for request dispatch
func GRPCHandlerFunc(g *grpc.Server, h http.Handler) http.Handler {
return h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 && strings.EqualFold(r.Header.Get(keyContentType), keyGrpcHeader) || h == nil {
g.ServeHTTP(w, r)
} else {
h.ServeHTTP(w, r)
}
}), &http2.Server{})
}

Comment ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/zakums06/go-scaffold.git
git@gitee.com:zakums06/go-scaffold.git
zakums06
go-scaffold
go-scaffold
v0.1.11

Search