func()

in mux.go [95:121]


func (m *mux) withGRPCInsecure(next http.Handler, errLog *log.Logger) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.TLS == nil && r.Method == "PRI" && len(r.Header) == 0 && r.URL.Path == "*" && r.Proto == "HTTP/2.0" {
			hijacker, ok := w.(http.Hijacker)
			if ok {
				conn, rw, err := hijacker.Hijack()
				if err != nil {
					panic(fmt.Sprintf("Hijack failed: %v", err))
				}
				defer conn.Close()

				// We just identify that we're dealing with a
				// prior-knowledge connection, and pass it straight
				// through to the gRPC server.
				preface := "PRI * HTTP/2.0\r\n\r\n"
				r := io.MultiReader(strings.NewReader(preface), rw, conn)
				pc, closed := newProxyConn(conn, r, conn)
				err = m.handleGRPC(nil, pc, closed, nil)
				if err != nil && errLog != nil {
					errLog.Printf("h2c handleGRPC (%s) returned an error: %s", conn.RemoteAddr(), err)
				}
				return
			}
		}
		next.ServeHTTP(w, r)
	})
}