git.iko.soy/typeable/oauth2-proxy
on request-rules help sign in
34 lines 807 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 if code == nil {
14 c := defaultStaticResponseCode
15 code = &c
16 }
17 return &staticResponseHandler{
18 code: *code,
19 upstream: upstream,
20 }
23// staticResponseHandler responds with a static response with the given response code.
24type staticResponseHandler struct {
25 code int
26 upstream string
29// ServeHTTP serves a static response.
30func (s *staticResponseHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
31 rw.Header().Set("GAP-Upstream-Address", s.upstream)
32 rw.WriteHeader(s.code)
33 fmt.Fprintf(rw, "Authenticated")