Repository navigation
Fix TLS startup, body-less responses, url decoding, charset and Content-Disposition - #39
Merged
Merged
Conversation
- TLS only starts once both a key and a certificate are set. A missing
or unreadable key or certificate, or a port that can't be bound, is
returned from `listen` before anything is served. Before, a TLS
feature without `app.ssl()` still tried port 443 and only printed
`WARNING: ...`, and a bad certificate left the app on plain HTTP.
- A request is answered once a handler returns `Flow::Stop` or a route
for its path and method has run, with or without a body. So
`res.redirect("/")` or a bare `204` is no longer turned into a 404.
Only middleware that passes the request on still ends in a 404/405.
- Request paths are percent-decoded segment by segment after splitting,
so url variables and literal routes see `Ada Lovelace` and `café`.
`%2F` stays inside its segment, `+` stays a `+`, and a segment that
decodes to `.` or `..` is a dot segment. The WASIp3 router decodes too.
- `octane::query` is public: `Query`, `decode` for queries and forms,
`percent_decode` for path segments, and `req.get_form()` for
`application/x-www-form-urlencoded` bodies.
- `res.charset("utf-8")` sends `text/html; charset=utf-8`, not
`text/html ;charset="utf-8"`. It applies to any Content-Type and in
any order, keeps a charset the type already names, and ignores a
value that isn't a token.
- `attachment_with_filename` sends `filename="name"` instead of
`filename = "name"`, escapes `"` and `\`, and adds an RFC 8187
`filename*` for names outside ASCII. It takes any `&str` now.
The test client no longer waits for a body after a 204 or 304.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes five problems that showed up while rewriting octane-examples.
TLS
With
rustlsoropenSSLenabled,listenused to spawn a TLS listener even whenapp.ssl()was never called. It bound port 443 with empty cert paths, printedWARNING: No such file or directory, and kept going. A bad certificate also only produced that warning, leaving the app on plain HTTP.Now:
listenloads the key and certificate and binds both ports before serving anything. A failure comes back as an error naming the files or the port, and nothing is left running.Responses without a body
A request counted as answered only if a body was set, so
res.redirect("/")orres.status(StatusCode::NoContent)became a 404. Now a request is answered once a handler returnsFlow::Stop, or once a route for its path and method has run. Without a body it goes out withContent-Length: 0, or no length for 204/304. Middleware that passes the request on still ends in Octane's 404/405. The fallback lives inOctane::route, so the HTTP/2 driver gets it too.Url decoding
Request paths are percent-decoded one segment at a time, after splitting:
/users/Ada%20Lovelace→req.vars.get("name") == Some("Ada Lovelace")/caf%C3%A9matches a/caféroute%2Fstays inside its segment+stays a+.or..is a dot segment, so%2e%2ecan't reach a handler as a variable, and above the root it's refused like..Route definitions aren't decoded. The WASIp3 router decodes too; I checked that under wasmtime.
octane::queryis now public:Querydecode, the query/form decoder (+is a space)percent_decodefor path segmentsreq.get_form(), which parsesapplication/x-www-form-urlencodedbodiesres.charsetres.charset("utf-8")producedtext/html ;charset="utf-8". It now producestext/html; charset=utf-8. The charset is added when the head is written, so it applies to any Content-Type, in any order. A type that already names a charset keeps it, and a value that isn't a token is ignored.attachment_with_filenameIt sent
filename = "x", with RustDebugescaping. It now sendsattachment; filename="x", escapes"and\, and adds an RFC 8187filename*=UTF-8''…for names outside ASCII. It takes any&strinstead of&'static str.Tests
tests/bodyless.rs,tests/forms.rs,tests/tls_config.rs(rustls and openSSL), decoding cases intests/url_variables.rs, plus unit tests for decoding, paths, charset and Content-Disposition.tests/common.rsno longer waits for a body after a 204/304.--no-default-features.cargo fmt --checkis clean.🤖 Generated with Claude Code