Skip to content

Request-target handling #897

Closed
Closed

Description

@Wonshtrum

Request-target can take 4 forms:

  • absolute form: http://user:[email protected]:8001/index.html?k=v#h
  • authority form: www.example.org:8001
  • origin form: /index.html?k=v#h
  • asterisk form: *

Let's ignore authority form and asterisk form as they serve a very precise purpose, respectively used for CONNECT requests and server wide OPTIONS requests. On the other hand it seems that absolute and origin forms can both be used for requests.

For standard requests, two things must be extracted for routing: the authority and the path. In addition to the request line, a Host header field must be sent in all HTTP/1.1 request messages. In the case of the origin form URI, the path is the entire URI, while the Host header bears the authority part. In the case of the absolute form both the path and authority part are derived from the URI. The Host header must still be present (for compatibility reasons) but will be ignored and rewritten with the authority found in the URI.

This is at least how I understand the HTTP/1.1 literature on the subject. Sozu doesn't seem to abide by those rules. More specifically I found two problematic cases. First sending a request to Sozu with a request-target in absolute form triggers a 400 response (invalid request). The reason being that Sozu HTTP request parser state machine transitions in the HasHost state when it encounters the absolute request-target (extracting the authority from it with Url::parse):

let host = match Url::parse(&request_line.uri)
.ok()
.and_then(|url| url.host_str().map(|s| s.to_string()))
{
Some(host) => host,
None => return (BufferMove::None, (RequestState::Initial).into_error()),
};
(
BufferMove::Advance(buf.offset(input)),
RequestState::HasHost(request_line, conn, host),
)

then enters in Error state as it encounters the Host header (which is considered invalid when already in HasHost state):

HeaderValue::Host(host) => match state {
RequestState::HasRequestLine(rl, conn) => RequestState::HasHost(rl, conn, host),
RequestState::HasLength(rl, conn, l) => {
RequestState::HasHostAndLength(rl, conn, host, l)
}
s => s.into_error(),
},

If you remove the Host header from the request then Sozu fails to recognize a malformed request. On the other hand, it correctly extracts the authority but uses the whole request-target (or URI) as path:

sozu/lib/src/http.rs

Lines 494 to 496 in 6f32ca5

self.fronts
.lookup(host.as_bytes(), uri.as_bytes(), method)
.with_context(|| "No cluster found")

This could be a deliberate design choice, but in practice, the lookup function names this parameter "path" and rules like PathBegin don't make sense on absolute URI.

pub fn lookup(&self, hostname: &[u8], path: &[u8], method: &Method) -> Option<Route> {

So in most cases, a request on Sozu with an absolute form request-target and no Host header will trigger a 404 response.

The severity of this issue is minimal as it seems to be considered bad practice to use absolute form request-target which multiplies the definitions of authority in the request without clear benefits. Most HTTP clients will automatically use or convert to origin form. We do not plan to fix this in the current version of Sozu, but as we are developing HTX on the side with completely new parsers the question rises again.

This issue is to acknowledge and document this behavior and potentially spark conversation on how to tackle this problem properly in the upcoming HTX.

Activity

  1. added this to the HTTP2 milestone on Mar 13, 2023
  2. FlorentinDUBOIS commented on May 2, 2026

    @FlorentinDUBOIS
    Collaborator

    Closing — superseded by the Kawa H1 parser + the post-Kawa H2 layer enforcement.

    The pre-Kawa code paths the issue cites (lib/src/protocol/http/parser/request.rs) no longer exist on main. Request-target normalisation now lives in two places:

    • H1: kawa (the external H1 parser, now in production) handles the four request-target forms per RFC 9112 §3.2 and rebuilds the request-line accordingly.
    • H2: lib/src/protocol/mux/pkawa.rs:801 explicitly rejects non-origin-form request paths for non-OPTIONS methods with H2Error::ProtocolError, matching RFC 9113 §8.3.1. Asterisk-form (*) is allowed only for OPTIONS.

    The original framing in this ticket was "acknowledge and document" pending HTX (Kawa) integration — that integration shipped, so the documentation question is answered by the current code + RFC compliance.

    If a specific absolute-form-on-H1 input is still misrouted on a current build, please open a fresh issue with a concrete repro (curl -v against sozu --version 1.1.x or main) and the observed-vs-expected behaviour — that ticket would be a real bug rather than a re-open of this design-era one.

  3. removed this from the HTTP2 milestone on May 2, 2026
  4. added this to the v2.0.0 milestone on May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions