Skip to content

refactor(kawa_h1): introduce Origin struct for backend connection management - #1206

Closed
FlorentinDUBOIS wants to merge 2 commits into
mainfrom
feat/rewrite-backend-refactor
Closed

FlorentinDUBOIS wants to merge 2 commits into
mainfrom
feat/rewrite-backend-refactor

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Summary

  • Introduce Origin struct to encapsulate all backend connection state (cluster_id, backend_id, backend, token, connected, socket) replacing 4 separate fields (backend, backend_socket, backend_token, backend_connection_status) on the Http struct
  • Add ResponseStream::DefaultAnswerKA variant (boxed) for keep-alive during default answers and ResponseStream::Swaping for mem::replace pattern
  • Update answers::get() return type from DefaultAnswerStream to (u16, bool, DefaultAnswerStream) tuple (keep_alive always false for now, PR B will add template-level detection)
  • Update upgrade_http in both http.rs and https.rs to destructure Origin when upgrading to WebSocket

Context

This is PR A in a series of 4 PRs splitting PR #1162 (rewrite/redirect feature):

  • PR A (this): Backend refactor (Origin struct) -- foundation
  • PR B: Flexible HTTP answer templates (BTreeMap refactoring, HttpsRedirect)
  • PR C: URL rewrite + redirection + custom headers
  • PR D: Basic authentication

Test plan

  • cargo check --workspace passes
  • cargo clippy --workspace -- no new warnings
  • cargo +nightly fmt -- all files formatted
  • cargo test --workspace -- all 69 tests pass

…agement

Replace inline backend connection fields (backend, backend_socket,
backend_token, backend_connection_status) on the Http struct with a
single `Option<Origin>` that encapsulates all backend state. Add
`ResponseStream::DefaultAnswerKA` variant for keep-alive during default
answers and `ResponseStream::Swaping` for mem::replace pattern. Update
answers::get() to return (u16, bool, DefaultAnswerStream) tuple in
preparation for template-level keep-alive detection.

Signed-off-by: Florentin Dubois <[email protected]>
- Fix typo: rename ResponseStream::Swaping to Swapping
- Fix backend_writable missing DefaultAnswerKA check that could cause
  writes to backend socket during default answer delivery
- Replace unreachable!() in connect_to_backend with proper error
  handling when cluster_id is missing on reconnection attempt

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Apr 28, 2026
…chema

Lay the wire schema for the bundled feature work that brings PR #1206..#1210
onto current main. Wave 1 of a multi-wave implementation; subsequent waves
land the runtime engine, mux integration, auth helper, e2e tests, and docs.

Cluster gains four fields: per-cluster `answers` (status code → template body)
at field 9, `https_redirect_port` at 10, `authorized_hashes` at 11, and
`www_authenticate` realm at 12. RequestHttpFrontend gains eight: `redirect`
policy at 8, `required_auth` at 9, `redirect_scheme` at 10, `redirect_template`
at 11, `rewrite_host`/`rewrite_path`/`rewrite_port` at 12-14, and a repeated
`headers` list at 15. Listener configs gain a parallel `answers` map at 31
(HttpListenerConfig) and 43 (HttpsListenerConfig); the legacy
`CustomHttpAnswers http_answers` field is preserved on the wire so existing
state files round-trip — the runtime will read both for one minor.

New top-level enums RedirectPolicy / RedirectScheme / HeaderPosition and a
Header message land alongside. An empty `Header.val` deletes the named header
(HAProxy `del-header` parity).

prost stops auto-deriving Hash/Eq once a message holds a map field, so the
build script gains explicit `#[derive(Hash, Eq)]` for Cluster,
HttpListenerConfig, HttpsListenerConfig, UpdateHttpListenerConfig, and
UpdateHttpsListenerConfig. Existing initializers grow a `..Default::default()`
fallthrough so this commit is a pure additive scaffolding step — no runtime
behaviour changes yet.

Signed-off-by: Florentin Dubois <[email protected]>
jrcribb pushed a commit to jrcribb/sozu that referenced this pull request Aug 10, 2026
…chema

Lay the wire schema for the bundled feature work that brings PR sozu-proxy#1206..sozu-proxy#1210
onto current main. Wave 1 of a multi-wave implementation; subsequent waves
land the runtime engine, mux integration, auth helper, e2e tests, and docs.

Cluster gains four fields: per-cluster `answers` (status code → template body)
at field 9, `https_redirect_port` at 10, `authorized_hashes` at 11, and
`www_authenticate` realm at 12. RequestHttpFrontend gains eight: `redirect`
policy at 8, `required_auth` at 9, `redirect_scheme` at 10, `redirect_template`
at 11, `rewrite_host`/`rewrite_path`/`rewrite_port` at 12-14, and a repeated
`headers` list at 15. Listener configs gain a parallel `answers` map at 31
(HttpListenerConfig) and 43 (HttpsListenerConfig); the legacy
`CustomHttpAnswers http_answers` field is preserved on the wire so existing
state files round-trip — the runtime will read both for one minor.

New top-level enums RedirectPolicy / RedirectScheme / HeaderPosition and a
Header message land alongside. An empty `Header.val` deletes the named header
(HAProxy `del-header` parity).

prost stops auto-deriving Hash/Eq once a message holds a map field, so the
build script gains explicit `#[derive(Hash, Eq)]` for Cluster,
HttpListenerConfig, HttpsListenerConfig, UpdateHttpListenerConfig, and
UpdateHttpsListenerConfig. Existing initializers grow a `..Default::default()`
fallthrough so this commit is a pure additive scaffolding step — no runtime
behaviour changes yet.

Signed-off-by: Florentin Dubois <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants