mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-09-30 03:31:27 +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:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mbland/hmacauth"
|
||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
|
||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
|
||||
"github.com/yhat/wsutil"
|
||||
)
|
||||
@@ -76,7 +77,12 @@ type httpUpstreamProxy struct {
|
||||
// ServeHTTP proxies requests to the upstream provider while signing the
|
||||
// request headers
|
||||
func (h *httpUpstreamProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.Header().Set("GAP-Upstream-Address", h.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 = h.upstream
|
||||
|
||||
// TODO (@NickMeves) - Deprecate GAP-Signature & remove GAP-Auth
|
||||
if h.auth != nil {
|
||||
req.Header.Set("GAP-Auth", rw.Header().Get("GAP-Auth"))
|
||||
h.auth.SignRequest(req)
|
||||
|
||||
Reference in New Issue
Block a user