omjadas / hudsucker

Intercepting HTTP/S proxy
https://crates.io/crates/hudsucker
Apache License 2.0
211 stars 37 forks source link

[Feature] Use type Option for handler #7

Closed zu1k closed 3 years ago

zu1k commented 3 years ago

In the current version, we need to pass three handlers to use hudsucker, including http_handler, incoming_message_handler and outgoing_message_handler.

I think many times the user may not need to handle everything and can use Option type, the user only needs to use Some to specify what needs to be handled and just pass None for things that are not of concern.

This would require the hudsucker to determine if the request or response is need to be handled by the user function, but I believe it would be more user friendly and flexible for crate users. And in this way, the example does not need an additional NoopHandler.

omjadas commented 3 years ago

I do agree that the handlers should probably be optional, I will try and get this done in a few days.

omjadas commented 3 years ago

Due to the complexities of using Option with type parameters, I decided to just move the no-op handlers into the crate so that external users can use them without having to re-implement. Released in v0.4.2.