Skip to main content

Module http

Module http 

Source
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.example is not a loopback host.
origin_ok
An Origin is 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-Length body bytes.
read_request_with
read_request for a listener with a bearer token (an exposed listener, see InferProxy::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 the Host need 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.