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
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Changed
RequestPolicy.max_body_bytes (STARIO_REQUESTS_MAX_BODY_BYTES) is now
the default limit for one read, not a cap for the server. A handler
passes max_size= to body() or stream() to accept more or less. An
upload route reads await c.req.body(max_size=6_000_000), and every
other route keeps the default.
The server no longer answers 413 before the handler runs when Content-Length is above the default. The read raises 413 instead. It
checks the declared length first, so it allocates nothing and sends no 100 Continue. Only a length above 2^31-1 bytes still gets a 413 before
the handler.
A body that the handler does not read drains up to the default, then the
HTTP/1 connection closes. A small declared body (256 KiB or less) still
drains and keeps the connection.
An HTTP/1 close while the client still sends a body is a lingering close
(RFC 9112 9.6): the server sends FIN after the response, then reads and
drops input for up to 2 seconds. Before, the close sent RST, and a
browser in the middle of an upload could lose the 413 and show a reset.
StaticFiles and Assets register only the GET route; it answers HEAD.
A GET route also answers HEAD (RFC 9110 9.3.2). The handler runs with c.req.method == "HEAD", and the server drops the body. Before, HEAD on
a GET route was 405, and each route needed a HEAD twin. An explicit HEAD
route still wins. The Allow header of a 405 now lists HEAD next to GET.
read_signals() reads the datastar query parameter for HEAD, as for
GET.
A HEAD response ends at its headers (RFC 9112 6.3). The connection then
serves the next request, and later write() / end() calls are no-ops.
For HEAD, c.disconnect resolves and c.disconnected is true once the
response is sent, so c.alive() stops an SSE handler. Before, an SSE
handler kept running under HEAD and held a keep-alive connection.
Added
stream(max_size=) limits the total bytes of a streamed body.
read_signals(req, max_size=) passes the limit to body(), for signals
that carry a FileSignal.
stario.forms: read_form(req) returns a Form with the text fields and
the uploaded files of an HTML form. GET and HEAD read the query string.
Other methods read an application/x-www-form-urlencoded or multipart/form-data body. Multipart bodies stream: each file is an UploadFile in a SpooledTemporaryFile that moves to disk past spool_size. Writes to disk and await upload.read() run in a thread,
so the event loop keeps serving. A cancelled request waits for that
thread before it closes the spool. Form.get / getlist / items / as_dict match req.query. max_size, max_fields, max_field_size, max_files, and max_file_size limit the body (413). A malformed body is 400, and another Content-Type is 415.
RequestBodyError accepts 415.
The test client quotes multipart names and filenames as browsers do
(" as %22), not with backslashes. read_form decodes %22, %0D, and %0A in names and filenames back to ", CR, and LF.
same_origin(trusted_origins=[...]) lets a listed origin post cross-site
(a payment return), and same_origin(exempt=["/hooks"]) skips the check
under a path prefix. The prefix matches the path as sent, so /hooks%2Fx (one segment for the router) is not exempt. The docstring
now names same_origin() as the CSRF protection for current browsers:
CSRF tokens would only add browsers from before about 2023.
stario.cookies.SignedCookie: a cookie with a JSON payload that the
client can read but not change. set(w, data) signs it with HMAC-SHA256,
and get(req) returns a SignedValue (data, issued_at, expires_at, age) only when the signature is valid and the expiry, which the server
checks, has not passed. The first of keys signs and every key verifies,
for rotation. Each key is 32 bytes or more. The signing key is derived
from the key and the cookie name, so a value cannot move to another
cookie. A value past about 3.9 KB raises an error instead of being
dropped by the browser. The defaults are HttpOnly, Secure, and SameSite=Lax.
set_cookie, delete_cookie, and SignedCookie raise StarioError for a __Host- name without secure=True, path="/", and no domain, and for a __Secure- name without secure=True. Browsers drop such a cookie
without an error.