mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-30 15:00:51 +02:00
proxy: use middleware to manage request flow
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>
This commit is contained in:
parent
70c5553d3c
commit
782ffbeb3e
17 changed files with 834 additions and 839 deletions
26
internal/middleware/cors.go
Normal file
26
internal/middleware/cors.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
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))
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue