Feature: Add Pre-request and Post-response Hooks to Tunnel Options
Summary
Introduce hooks in the tunnel options to allow users to manipulate requests before sending and responses after receiving. This would enable flexible modifications, logging, and advanced behavior customization by exposing new handlers.
Proposed API
Add the following hooks as optional parameters to tunnelOptions:
onRequest: func(req) {
// User-defined logic to manipulate or inspect the request
}
onResponse: func(resp) {
// User-defined logic to manipulate or inspect the response
}
onRequest: Invoked before forwarding a request;
onResponse: Invoked after a response is received, before returning to client.
Benefits
- Enables powerful custom behaviors.
- Facilitates debugging, logging, rewriting, authentication, or access control.
- Unlocks new integrations with minimal core changes.
Implementation Notes
- Hooks should be added as optional fields to the main options struct (
tunnelOptions).
- Document the expected function signatures for both hooks.
- Ensure hooks are called at appropriate moments in the proxy lifecycle.
Example:
opts := tunnelOptions{
onRequest: func(req *http.Request) {
// modify req.Header, log, etc.
},
onResponse: func(resp *http.Response) {
// inspect resp, add custom headers, log, etc.
},
}
This feature makes gotunnel significantly more extensible for various advanced or custom use cases.
Feature: Add Pre-request and Post-response Hooks to Tunnel Options
Summary
Introduce hooks in the tunnel options to allow users to manipulate requests before sending and responses after receiving. This would enable flexible modifications, logging, and advanced behavior customization by exposing new handlers.
Proposed API
Add the following hooks as optional parameters to
tunnelOptions:onRequest: Invoked before forwarding a request;onResponse: Invoked after a response is received, before returning to client.Benefits
Implementation Notes
tunnelOptions).Example:
This feature makes gotunnel significantly more extensible for various advanced or custom use cases.