Skip to content

Commit

Permalink
Merge pull request #356 from stephenafamo/unrwap-writer
Browse files Browse the repository at this point in the history
Add WrappingResponseWriter interface
  • Loading branch information
aarondl committed Nov 19, 2023
2 parents 16b99bb + 12fc261 commit 8fc0b1f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ type UnderlyingResponseWriter interface {
UnderlyingResponseWriter() http.ResponseWriter
}

// WrappingResponseWriter is a response writer that can be unwrapped
// is is used identically to [UnderlyingResponseWriter] but uses the standard
// set out in [http.ResponseContoller]
type WrappingResponseWriter interface {
Unwrap() http.ResponseWriter
}

// ClientState represents the client's current state and can answer queries
// about it.
type ClientState interface {
Expand Down Expand Up @@ -185,6 +192,11 @@ func MustClientStateResponseWriter(w http.ResponseWriter) *ClientStateResponseWr
continue
}

if u, ok := w.(WrappingResponseWriter); ok {
w = u.Unwrap()
continue
}

panic(fmt.Sprintf("ResponseWriter must be a ClientStateResponseWriter or UnderlyingResponseWriter in (see: authboss.LoadClientStateMiddleware): %T", w))
}
}
Expand Down

0 comments on commit 8fc0b1f

Please sign in to comment.