volatiletech / authboss

The boss of http auth.
MIT License
3.79k stars 204 forks source link

Add WrappingResponseWriter interface #356

Closed stephenafamo closed 9 months ago

aarondl commented 9 months ago

This doesn't seem necessary with the other PR that adds the standard interface implementation?

stephenafamo commented 9 months ago

This one is necessary even with that.

The other pr (#350) makes the clientStateResponseWriter compatible with packages that need to inspect the underlying response writer.

This PR prevents a panic if the response writer was wrapped with a "Standard Library Wrapper" in between the ClientStateMiddleware and something that checks for it.

For example:

r := chi.NewRouter()

// loading the client state
r.Use(ab.LoadClientStateMiddleware)

// this will wrap the client state handler with an `UnwrappableResponseWriter`
r.Use(middleware.Logging)

// This will panic because it does not know how to unwrap the logging middleware
r.Use(ab.Middleware2(...))