git.iko.soy/typeable/oauth2-proxy
on 597ffeb help sign in
38 lines 952 B history raw
1package upstream
3import (
4 "fmt"
5 "net/http"
6)
8const defaultStaticResponseCode = 200
10// newStaticResponseHandler creates a new staticResponseHandler that serves a
11// a static response code.
12func newStaticResponseHandler(upstream string, code *int) http.Handler {
13 return &staticResponseHandler{
14 code: derefStaticCode(code),
15 upstream: upstream,
16 }
19// staticResponseHandler responds with a static response with the given response code.
20type staticResponseHandler struct {
21 code int
22 upstream string
25// ServeHTTP serves a static response.
26func (s *staticResponseHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
27 rw.Header().Set("GAP-Upstream-Address", s.upstream)
28 rw.WriteHeader(s.code)
29 fmt.Fprintf(rw, "Authenticated")
32// derefStaticCode returns the derefenced value, or the default if the value is nil
33func derefStaticCode(code *int) int {
34 if code != nil {
35 return *code
36 }
37 return defaultStaticResponseCode