Skip to content

Remove async-trait - #333

Merged
FalkWoldmann merged 3 commits into
masterfrom
remove-async-trait
Oct 20, 2026
Merged

FalkWoldmann merged 3 commits into
masterfrom
remove-async-trait

Conversation

@FalkWoldmann

@FalkWoldmann FalkWoldmann commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

This drops async-trait. The adapter traits now return impl Future + Send, and since those aren't dyn-compatible, MockServer holds a ServerAdapter enum instead of a trait object. The HttpClient trait had a single impl, so it's gone and callers use HttpMockHttpClient directly. tls-detect goes too, because its Read trait was the other reason we needed async-trait: the server now tells TLS from plain HTTP by peeking at the first byte.

the tls-detect cargo feature is gone, noted as a breaking change in the CHANGELOG. As a side effect it fixes a debug-build overflow panic in tls-detect and a double copy in TcpStreamPeekBuffer::advance after a partial peek

@FalkWoldmann

Copy link
Copy Markdown
Member Author

@claude

@claude

claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Claude finished @FalkWoldmann's task in 9s —— View job


Hi @FalkWoldmann, your comment only contained @claude, so I don't know what you'd like me to do. I haven't read or changed any code.

I can help with things like:

  • Review the PR. I'd check the ServerAdapter enum refactor, the first-byte TLS detection in src/server/tls.rs and src/server/transport.rs, and the removal of the HttpClient trait and the tls-detect feature.
  • Check specific concerns. Examples are the partial-peek handling in TcpStreamPeekBuffer::advance, the breaking-change note in the CHANGELOG, and the test coverage in tests/examples/https_tests.rs.
  • Make changes. Tell me what to implement, fix, or clean up and I'll push it to this branch.

Tell me which of these you want, or give me a different instruction, and I'll start.
· branch: remove-async-trait

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@FalkWoldmann

Copy link
Copy Markdown
Member Author

@claude review

@claude

claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Claude finished @FalkWoldmann's task in 20s —— View job


Review of #333: Remove async-trait

I read the full diff but didn't build or run the tests, so the notes below come from reading the code.

Verdict: Looks good to merge. I found no blocking issues, only the minor notes below.

What I checked

  • ServerAdapter enum (src/api/adapter.rs): The dispatch! macro mirrors the cfg(feature = "remote") gating on the Remote variant. Every trait method has a forwarding wrapper, including the proxy and record ones. The + Send bounds on the trait futures keep the public async API usable inside tokio::spawn. The comment explaining why is useful.
  • HttpClient removal: Arc<HttpMockHttpClient> replaces the trait object in builder.rs and handler.rs. This is fine given there was only one impl, and it drops the dyn indirection.
  • TLS detection (src/server/tls.rs):
    • A single-byte peek is simpler than the old buffer. It cannot spin on a partial prefix, and it removes the advance double-copy and overflow issues by deleting that code.
    • 0x16 (handshake) can't collide with the start of an HTTP/1 request line, the h2 preface (PRI), or a leading CRLF.
    • The unit tests cover the interesting cases: a real rustls ClientHello, a split first byte, HTTP/1, the h2 preface, EOF, and a blocked peek.
  • transport.rs: A peek error now returns Ok(()) with a debug log instead of falling through to the plain-HTTP path. That seems right, and the RST test covers it.
  • Integration test: serves_http_and_https_on_the_same_port checks that HTTP and HTTPS work on one port, using the bundled CA, so it doesn't depend on the OS trust store.
  • CHANGELOG: The tls-detect feature removal is listed under breaking changes.

Minor notes (non-blocking)

  1. SSLv2-style hello: tls-detect may also have recognised the legacy SSLv2-framed ClientHello (first byte 0x80). The new check accepts only ContentType::Handshake. rustls doesn't support SSLv2 anyway, so those clients would have failed the handshake regardless. A one-line note in the CHANGELOG isn't needed, but the doc comment could mention it.
  2. Peek on a half-open connection: A client that connects and sends nothing keeps the connection task parked in peek indefinitely. The old code behaved the same way, so this isn't a regression. If you want hardening later, wrap the peek in a timeout.
  3. #[allow(unused_must_use)] in handler.rs: This was already there and is unrelated, so I'm only mentioning that I noticed it.
    · branch: remove-async-trait

@FalkWoldmann
FalkWoldmann merged commit d6ad0ec into master Oct 20, 2026
16 checks 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