Skip to content

Fix TLS startup, body-less responses, url decoding, charset and Content-Disposition - #39

Merged
Daksh14 merged 1 commit into
developfrom
fix-tls-bodyless-decoding
Nov 19, 2026
Merged

Daksh14 merged 1 commit into
developfrom
fix-tls-bodyless-decoding

Conversation

@Daksh14

@Daksh14 Daksh14 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Fixes five problems that showed up while rewriting octane-examples.

TLS

With rustls or openSSL enabled, listen used to spawn a TLS listener even when app.ssl() was never called. It bound port 443 with empty cert paths, printed WARNING: No such file or directory, and kept going. A bad certificate also only produced that warning, leaving the app on plain HTTP.

Now:

  • TLS starts only when both a key and a certificate are set.
  • Setting only one of them is an error.
  • listen loads 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("/") or res.status(StatusCode::NoContent) became a 404. Now a request is answered once a handler returns Flow::Stop, or once a route for its path and method has run. Without a body it goes out with Content-Length: 0, or no length for 204/304. Middleware that passes the request on still ends in Octane's 404/405. The fallback lives in Octane::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%A9 matches a /café route
  • %2F stays inside its segment
  • + stays a +
  • a segment that decodes to . or .. is a dot segment, so %2e%2e can'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::query is now public:

  • Query
  • decode, the query/form decoder (+ is a space)
  • percent_decode for path segments
  • req.get_form(), which parses application/x-www-form-urlencoded bodies

res.charset

res.charset("utf-8") produced text/html ;charset="utf-8". It now produces text/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_filename

It sent filename = "x", with Rust Debug escaping. It now sends attachment; filename="x", escapes " and \, and adds an RFC 8187 filename*=UTF-8''… for names outside ASCII. It takes any &str instead of &'static str.

Tests

  • New: tests/bodyless.rs, tests/forms.rs, tests/tls_config.rs (rustls and openSSL), decoding cases in tests/url_variables.rs, plus unit tests for decoding, paths, charset and Content-Disposition.
  • tests/common.rs no longer waits for a body after a 204/304.
  • The CI feature matrix passes: default, the rustls set, openSSL, --no-default-features.
  • cargo fmt --check is clean.
  • No new clippy warnings in the changed files.
  • The WASIp3 guest builds and serves.

🤖 Generated with Claude Code

- 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>
@Daksh14
Daksh14 merged commit fcc92e6 into develop Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant