Expand description
Minimal HTTP/1.1 for the loopback listener, and the request allowlist.
One request per connection (Connection: close), so there is no
pipelining and no keep-alive state to get wrong. Only origin-form
targets are accepted: an absolute-form target (GET http://host/...)
is how a forward proxy becomes an open relay, so it is refused.
Structs§
- Head
- A parsed request head.
Functions§
- ct_eq
- Constant-time equality of two byte strings of any length.
- loopback_
host host[:port]is a loopback name or address (DNS-rebinding guard). The port, when present, must be digits:127.0.0.1:80.evil.exampleis not a loopback host.- origin_
ok - An
Originis acceptable when absent or itself loopback: a web page on another origin must not drive a local model through the proxy. - parse_
head - Parse a head (without the terminating blank line).
- path_
allowed - Paths the proxy forwards: the OpenAI-compatible surface, the servers’
health endpoints, and Ollama’s inference and read-only endpoints. Model
management (
/api/pull,/api/delete,/api/create, …) is refused. - read_
request - Read one request: head, then exactly
Content-Lengthbody bytes. - read_
request_ with read_requestfor a listener with a bearer token (an exposed listener, seeInferProxy::start_exposed). The token is checked right after the head, before any body is read, and then removed from the request: it is this listener’s credential, not the model server’s. With a token theHostneed not be loopback (the credential, not the address, is the guard); without one it must be.- safe_
header_ value - Visible ASCII only, bounded: a value that came from a server or a peer must not be able to end the header block.
- validate_
path - Origin-form path with no way to change the authority, climb out of the route, or smuggle control bytes.
- write_
error - A complete JSON error response.
- write_
head - Write a status line and headers; the body that follows is delimited by closing the connection.