mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-18 13:18:26 +02:00
Fix conversion of static responses in upstreams
This commit is contained in:
@@ -56,6 +56,7 @@ func (m *multiUpstreamProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request
|
||||
|
||||
// registerStaticResponseHandler registers a static response handler with at the given path.
|
||||
func (m *multiUpstreamProxy) registerStaticResponseHandler(upstream options.Upstream) {
|
||||
logger.Printf("mapping path %q => static response %d", upstream.Path, derefStaticCode(upstream.StaticCode))
|
||||
m.serveMux.Handle(upstream.Path, newStaticResponseHandler(upstream.ID, upstream.StaticCode))
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,8 @@ const defaultStaticResponseCode = 200
|
||||
// newStaticResponseHandler creates a new staticResponseHandler that serves a
|
||||
// a static response code.
|
||||
func newStaticResponseHandler(upstream string, code *int) http.Handler {
|
||||
if code == nil {
|
||||
c := defaultStaticResponseCode
|
||||
code = &c
|
||||
}
|
||||
return &staticResponseHandler{
|
||||
code: *code,
|
||||
code: derefStaticCode(code),
|
||||
upstream: upstream,
|
||||
}
|
||||
}
|
||||
@@ -32,3 +28,11 @@ func (s *staticResponseHandler) ServeHTTP(rw http.ResponseWriter, req *http.Requ
|
||||
rw.WriteHeader(s.code)
|
||||
fmt.Fprintf(rw, "Authenticated")
|
||||
}
|
||||
|
||||
// derefStaticCode returns the derefenced value, or the default if the value is nil
|
||||
func derefStaticCode(code *int) int {
|
||||
if code != nil {
|
||||
return *code
|
||||
}
|
||||
return defaultStaticResponseCode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user