7 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
8 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
11const defaultStaticResponseCode = 200
13// newStaticResponseHandler creates a new staticResponseHandler that serves a
14// a static response code.
15func newStaticResponseHandler(upstream string, code *int) http.Handler {
16 return &staticResponseHandler{
17 code: derefStaticCode(code),
22// staticResponseHandler responds with a static response with the given response code.
23type staticResponseHandler struct {
28// ServeHTTP serves a static response.
29func (s *staticResponseHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
30 scope := middleware.GetRequestScope(req)
31 // If scope is nil, this will panic.
32 // A scope should always be injected before this handler is called.
33 scope.Upstream = s.upstream
35 rw.WriteHeader(s.code)
36 _, err := fmt.Fprintf(rw, "Authenticated")
38 logger.Errorf("Error writing static response: %v", err)
42// derefStaticCode returns the derefenced value, or the default if the value is nil
43func derefStaticCode(code *int) int {
47 return defaultStaticResponseCode
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list