Fix conversion of static responses in upstreams

This commit is contained in:
Joel Speed
2020-08-31 16:54:01 +01:00
parent 73f0094486
commit b40517bbe3
5 changed files with 33 additions and 16 deletions
+9 -5
View File
@@ -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
}