mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
proxy: remove duplicate error handling in New proxy: remove routeConfigs in favor of using gorilla/mux proxy: add proxy specific middleware proxy: no longer need to use middleware / handler to check if valid route. Can use build in 404 mux. internal/middleware: add cors bypass middleware Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
26 lines
893 B
Go
26 lines
893 B
Go
package middleware // import "github.com/pomerium/pomerium/internal/middleware"
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/pomerium/pomerium/internal/telemetry/trace"
|
|
)
|
|
|
|
// CorsBypass is middleware that takes a target handler as a paramater,
|
|
// if the request is determined to be a CORS preflight request, that handler
|
|
// is called instead of the normal handler chain.
|
|
func CorsBypass(target http.Handler) func(next http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
ctx, span := trace.StartSpan(r.Context(), "middleware.CorsBypass")
|
|
defer span.End()
|
|
if r.Method == http.MethodOptions &&
|
|
r.Header.Get("Access-Control-Request-Method") != "" &&
|
|
r.Header.Get("Origin") != "" {
|
|
target.ServeHTTP(w, r.WithContext(ctx))
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
}
|
|
}
|