mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-22 04:32:02 +02:00
Move Logging to Middleware Package (#1070)
* Use a specialized ResponseWriter in middleware * Track User & Upstream in RequestScope * Wrap responses in our custom ResponseWriter * Add tests for logging middleware * Inject upstream metadata into request scope * Use custom ResponseWriter only in logging middleware * Assume RequestScope is never nil
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
|
||||
)
|
||||
|
||||
const fileScheme = "file"
|
||||
@@ -37,6 +39,10 @@ type fileServer struct {
|
||||
// ServeHTTP proxies requests to the upstream provider while signing the
|
||||
// request headers
|
||||
func (u *fileServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.Header().Set("GAP-Upstream-Address", u.upstream)
|
||||
scope := middleware.GetRequestScope(req)
|
||||
// If scope is nil, this will panic.
|
||||
// A scope should always be injected before this handler is called.
|
||||
scope.Upstream = u.upstream
|
||||
|
||||
u.handler.ServeHTTP(rw, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user