google / go-safeweb

Secure-by-default HTTP servers in Go.
Apache License 2.0
1.43k stars 81 forks source link

Provide a way to check if a ServeMuxConfig has a specific interceptor installed. #317

Closed empijei closed 3 years ago

empijei commented 3 years ago

It would be useful to have helpers like (*ServeMuxConfig).Has(Interceptor) bool and (*ServeMuxConfig).Get(Interceptor) (Interceptor, bool).

These would facilitate some use cases:

kele commented 3 years ago

Let me focus on the use cases first.

Tests: it would make it possible to test if a default configuration has successfully installed the right set of interceptors

I'd be in favor of testing behavior over implementation here.

Orchestrators: this would allow orchestrated plugins to be installed in separate moments and easily share some configuration

Could you come up with a concrete example here?

empijei commented 3 years ago

I'd be in favor of testing behavior over implementation here.

Makes sense, but it would make people re-test their interceptors to just test the code the installs them.

That said, nothing prevents people from wrapping a servemux config with one that keeps tabs on what was installed, so if people really need this feature for very advanced use cases they can implement it themselves (and we keep the framework simpler).