You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Question] Hook to rewrite requests and responses #1178
Context
I'm building a proxy based on sozu (called Sozune) and would like to intercept HTTP requests and responses to modify them before they are sent or received.
Need
I'm looking for a simple way to add a hook or extension point to:
rewrite or modify requests (path, headers, etc.) before routing;
rewrite or modify responses (headers, status, etc.) before sending them back to the client.
Ideally, this would just allow plugging a function or callback at those two stages in the pipeline.
Hi! Thanks for your interest in Sozu.
Unfortunately, Sozu currently doesn't have hooks to customize its behavior.
rewrite or modify requests (path, headers, etc.) before routing;
rewrite or modify responses (headers, status, etc.) before sending them back to the client.
The closest thing to what you describe is what's developed in #1162 (see #1161), which includes URL rewriting and header editing on requests/responses on every frontend. But there is no logic, you can only add constant headers and rewrite URL using regex captures and templating.
Ideally, this would just allow plugging a function or callback at those two stages in the pipeline.
Sozu technically has explicitely those hooks internally:
That's where it processes and generates the forwarding headers and add the Sozu-id. However, requests goes through this before they are linked to a cluster/frontend, so if you want to add custom logic per frontend or per cluster, it would be hard here. You can look how it is done in #1162:
Responses are necessarily handled after the cluster/frontend was selected, so, if the context was populated with the relevant information, you can use this directly, like here for example:
I really want Sozu to expose this kind of customisable hooks in the future, your feedback on how you would like it to be done, and what you think of the current code paths would be greatly appreciated.
Cross-link for tracking: the broader hook design has now landed as #1239 (Programmable Rust hooks for sōzu — design proposal). The proposal covers exactly the request/response rewrite scenarios you raised here. Continuing the discussion on #1239 going forward; leaving this issue open for now since Wonshtrum's detailed walk-through is the canonical context for newcomers.
Activity
Wonshtrum commentedon Oct 16, 2025
Hi! Thanks for your interest in Sozu.
Unfortunately, Sozu currently doesn't have hooks to customize its behavior.
The closest thing to what you describe is what's developed in #1162 (see #1161), which includes URL rewriting and header editing on requests/responses on every frontend. But there is no logic, you can only add constant headers and rewrite URL using regex captures and templating.
Sozu technically has explicitely those hooks internally:
sozu/lib/src/protocol/kawa_h1/editor.rs
Line 80 in 85bc468
sozu/lib/src/protocol/kawa_h1/editor.rs
Line 278 in 85bc468
That's where it processes and generates the forwarding headers and add the Sozu-id. However, requests goes through this before they are linked to a cluster/frontend, so if you want to add custom logic per frontend or per cluster, it would be hard here. You can look how it is done in #1162:
sozu/lib/src/protocol/kawa_h1/mod.rs
Lines 1262 to 1403 in 448ece3
Responses are necessarily handled after the cluster/frontend was selected, so, if the context was populated with the relevant information, you can use this directly, like here for example:
sozu/lib/src/protocol/kawa_h1/editor.rs
Line 384 in 448ece3
I really want Sozu to expose this kind of customisable hooks in the future, your feedback on how you would like it to be done, and what you think of the current code paths would be greatly appreciated.
Shine-neko commentedon Jan 23, 2026
@Wonshtrum Thanks for the detailed explanation and the code pointers!
Looking at the
HttpContextimplementation withParserCallbacks, I think a simple trait-based approach could work well:Users would register their hooks via a builder pattern:
Then inside on_request_headers() / on_response_headers(), Sozu would call the user hook if one is registered.
A few questions:
I'd be happy to look deeper into the code and propose a PR if this direction makes sense.
FlorentinDUBOIS commentedon May 5, 2026
Cross-link for tracking: the broader hook design has now landed as #1239 (
Programmable Rust hooks for sōzu — design proposal). The proposal covers exactly the request/response rewrite scenarios you raised here. Continuing the discussion on #1239 going forward; leaving this issue open for now since Wonshtrum's detailed walk-through is the canonical context for newcomers.FlorentinDUBOIS commentedon Oct 15, 2026
Tracked by #1239 (programmable Rust hooks design), which covers the request/response rewrite use case raised here. Closing in favour of #1239.