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
right now, sozu is built to handle very large requests: it only cares about the path and the Host header for routing (and, in some cases, the sticky session cookie). Once it has seen them, it starts forwarding data to the backend.
While this has been useful to handle some weird request (like very large cookies), it is limiting what we can do in routing. I'd like to add rules depending on the presence or content of some headers.
There are only 2 ways to do that:
allocate buffers to store the header content
put a hard limit on the request size: the request line or status line and all the headers should be smaller than the buffer size (the content can be streamed once we have parsed the request and done the routing)
This would make routing slightly slower in some cases (when we get the routing info but not all headers have come, which is rare), but would make parsing and routing easier, and allow more features
in lib/src/protocol/http/mod.rs, wait for all the headers to be parsed to start proxying
define a structure to represent a type of header and its position
issue: currently, buffering is defined around the BufferQueue struct that indicates parsing and streaming state: position of currently valid data, end of currently parsed data, position at which we start parsing again (in case of chunking, etc). Headers could point to data that is marked as parsed and ready to be shipped to the backend
is the current buffer structure still adapted?
we could use bytes::Bytes, which would make it easier to pass data around
do we adapt the BufferQueue to do a bit more?
the parser could generate a list of structures referring to the buffer, ie request line from here to there, Host header from here to there, etc. We could then apply filters to this list (which would make headers rewriting a bit easier)
define how header rules work. Can they be stacked, do we use them for routing? Do we use a list of filters instead of testing rules one by one?
note: those header changes are necessary for:
-HTTP/2 support ( #540 ) to separate the client and server HTTP 1 implementations and transmit data between HTTP1 and HTTP/2 parts
io_uring: with a clearer separation of the buffers, we will be able to lend them to the kernel to execute tasks list with io_uring
wasm plugins WebAssembly plugins #685: we should give access to the headers to wasm plugins, without having them parse again the headers
Status update on the original plan, against current main:
Wait for all headers before proxying — done. The legacy lib/src/protocol/http/ path is gone; H1 flows through kawa (lib/src/protocol/kawa_h1/) and the unified Mux session layer (lib/src/protocol/mux/). Router::connect runs route_from_request against a fully populated HttpContext before any backend connect, on both H1 (MuxClear) and H2 (MuxTls, shipped in feat(h2): HTTP/2 support via unified Mux session layer #1209). HTTPS listeners advertising h2 enforce buffer_size >= 16393 so the entire header block lands in one buffer.
Structured header representation — done. Headers are now kawa::Block::Header(kawa::Pair { key, val }) referencing the parser buffer, with structured access via HttpContext. Owned snapshots (HeaderEditSnapshot { key, val }) are taken at the routing edit boundary so downstream emission paths can mutate without aliasing the parser slab.
Buffer structure modernised — done.BufferQueue is removed. The block-list-over-Checkout shape from kawa replaced it. Not the bytes::Bytes originally speculated, but the same property: the parser yields a list of structures referring back into the buffer, with header positions usable for filtering.
Header rules — shipped as mutation in feat: HTTP answer templates, URL rewrite, redirect, custom headers, basic auth #1231 (merged 2026-04-28).RequestHttpFrontend.headers: repeated Header with HeaderPosition { REQUEST, RESPONSE, BOTH }, set/replace/delete semantics (empty val deletes by name, HAProxy del-header parity), and $HOST[n] / $PATH[n] capture substitution in rewrite templates. Applied at the wire emission boundary in mux/router.rs::apply_request_rewrites_and_headers (request side) and mux/shared.rs::apply_response_header_edits (response side, just before kawa.prepare).
Residual gap: matching frontends on a header value or presence is still not implemented — the router keys on (hostname, path, method). The closest active design vehicle is #1239 (programmable Rust hooks). If header-predicate routing matters as a separate concern, opening a fresh issue scoped narrowly to that — or contributing the predicate shape to #1239 — is the cleaner path forward.
Activity
Geal commentedon Jun 21, 2019
Plan:
lib/src/protocol/http/mod.rs, wait for all the headers to be parsed to start proxyingBufferQueuestruct that indicates parsing and streaming state: position of currently valid data, end of currently parsed data, position at which we start parsing again (in case of chunking, etc). Headers could point to data that is marked as parsed and ready to be shipped to the backendbytes::Bytes, which would make it easier to pass data aroundBufferQueueto do a bit more?Hostheader from here to there, etc. We could then apply filters to this list (which would make headers rewriting a bit easier)Geal commentedon Jul 29, 2021
note: those header changes are necessary for:
-HTTP/2 support ( #540 ) to separate the client and server HTTP 1 implementations and transmit data between HTTP1 and HTTP/2 parts
FlorentinDUBOIS commentedon May 2, 2026
Status update on the original plan, against current
main:Wait for all headers before proxying — done. The legacy
lib/src/protocol/http/path is gone; H1 flows through kawa (lib/src/protocol/kawa_h1/) and the unified Mux session layer (lib/src/protocol/mux/).Router::connectrunsroute_from_requestagainst a fully populatedHttpContextbefore any backend connect, on both H1 (MuxClear) and H2 (MuxTls, shipped in feat(h2): HTTP/2 support via unified Mux session layer #1209). HTTPS listeners advertisingh2enforcebuffer_size >= 16393so the entire header block lands in one buffer.Structured header representation — done. Headers are now
kawa::Block::Header(kawa::Pair { key, val })referencing the parser buffer, with structured access viaHttpContext. Owned snapshots (HeaderEditSnapshot { key, val }) are taken at the routing edit boundary so downstream emission paths can mutate without aliasing the parser slab.Buffer structure modernised — done.
BufferQueueis removed. The block-list-over-Checkoutshape from kawa replaced it. Not thebytes::Bytesoriginally speculated, but the same property: the parser yields a list of structures referring back into the buffer, with header positions usable for filtering.Header rules — shipped as mutation in feat: HTTP answer templates, URL rewrite, redirect, custom headers, basic auth #1231 (merged 2026-04-28).
RequestHttpFrontend.headers: repeated HeaderwithHeaderPosition { REQUEST, RESPONSE, BOTH }, set/replace/delete semantics (emptyvaldeletes by name, HAProxydel-headerparity), and$HOST[n]/$PATH[n]capture substitution in rewrite templates. Applied at the wire emission boundary inmux/router.rs::apply_request_rewrites_and_headers(request side) andmux/shared.rs::apply_response_header_edits(response side, just beforekawa.prepare).Residual gap: matching frontends on a header value or presence is still not implemented — the router keys on
(hostname, path, method). The closest active design vehicle is #1239 (programmable Rust hooks). If header-predicate routing matters as a separate concern, opening a fresh issue scoped narrowly to that — or contributing the predicate shape to #1239 — is the cleaner path forward.Closing as completed.