MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / preflightHandler

Function preflightHandler

examples/internal/gateway/handlers.go:51–57  ·  view source on GitHub ↗

preflightHandler adds the necessary headers in order to serve CORS from any origin using the methods "GET", "HEAD", "POST", "PUT", "DELETE" We insist, don't do this without consideration in production systems.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

49// CORS from any origin using the methods "GET", "HEAD", "POST", "PUT", "DELETE"
50// We insist, don't do this without consideration in production systems.
51func preflightHandler(w http.ResponseWriter, r *http.Request) {
52 headers := []string{"Content-Type", "Accept", "Authorization"}
53 w.Header().Set("Access-Control-Allow-Headers", strings.Join(headers, ","))
54 methods := []string{"GET", "HEAD", "POST", "PUT", "DELETE"}
55 w.Header().Set("Access-Control-Allow-Methods", strings.Join(methods, ","))
56 grpclog.Infof("Preflight request for %s", r.URL.Path)
57}
58
59// healthzServer returns a simple health handler which returns ok.
60func healthzServer(conn *grpc.ClientConn) http.HandlerFunc {

Callers 1

allowCORSFunction · 0.85

Calls 2

SetMethod · 0.80
HeaderMethod · 0.80

Tested by

no test coverage detected