refactor!: Simplify response and module APIs and fix server behaviour - #7
Merged
Merged
Conversation
Avoid entering and blocking a runtime from synchronous router configuration.
BREAKING CHANGE: Conflicting routes now cause a panic when mounting routes or enabling case-insensitive matching.
Snapshot shared partial handlers instead of draining their registrations, so starting one router does not remove partials from its clones or later runs.
BREAKING CHANGE: Different modules may execute concurrently across requests. A poisoned synchronous module no longer disables other modules.
BREAKING CHANGE: RouterOption gains AllowConcurrentModules, so exhaustive matches must handle the new variant.
BREAKING CHANGE: Callers of the generated __router_index method must use the declared handler name. An ordinary route explicitly named __router_index now mounts at /__router_index rather than /.
BREAKING CHANGE: Invalid or duplicate field initialisers and reserved names now produce errors.
BREAKING CHANGE: File credential setters replace earlier inline values. Explicit custom TLS acceptors retain precedence over credentials.
BREAKING CHANGE: Invalid response statuses or metadata produce a temporary failure. Multiple language tags are quoted, and empty errors omit the space.
BREAKING CHANGE: Stopping or dropping the server cancels unfinished connection tasks after the configured drain period, which defaults to zero. Admission limits and stage deadlines remain opt-in.
BREAKING CHANGE: Response fields are private. Changing the status or payload kind requires replacing the response.
BREAKING CHANGE: Request hooks receive &self and synchronous modules require Sync. Concurrent mode permits overlapping calls to the same module.
BREAKING CHANGE: The logger feature, enable_default_logger, and set_log_level are removed. Applications must install their own logging backend.
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.
Windmark's router could lose registered partials when starting a server, block the runtime during asynchronous module attachment, and alter captured parameters during case-insensitive lookup. Response fields also allowed conflicting text and binary payloads, and the library handled application logging.
This change fixes those behaviours, gives responses a single explicit payload, moves module state synchronisation into module implementations, and lets applications initialise their own logger. It prepares Windmark 0.8.0 and Rossweisse 0.0.4.
Changes
Router::bind,Server::local_addr, controlled shutdown, and optional connection caps and stage deadlines. The existingRouter::runremains available.response-macrosandloggerfeatures, and eliminate thepastedependency.Consumer Migration
Responses
Replace response macros with closures. Asynchronous handlers can return an
asyncblock. Handlers that move captured state into an asynchronous block may need to clone it for each request.Response fields are private. Use accessors to read or edit content and metadata; replace the response to change its status or switch between text and binary payloads.
Numeric statuses, binary constructors, and optional MIME inference remain available. Internal binary statuses 21 and 22 still map to status 20 on the wire.
Modules
Await asynchronous attachment:
Request hooks now receive
&self, while attachment hooks retain&mut self. Synchronous modules requireSend + Sync. Mutable state requires appropriate synchronisation, such as an atomic counter:The same receiver change applies to asynchronous request hooks. Module hook phases remain exclusive across requests by default.
AllowConcurrentModulespermits overlapping invocations of the same module; exhaustive matches onRouterOptionmust handle this new variant. A poisoned synchronous module no longer disables unrelated modules.Logging
Remove the
loggerfeature and configure a backend for the application. For example, addpretty_env_loggeras an application dependency:Rossweisse
Call an index handler by its declared name rather than the generated
__router_index:An ordinary route named
__router_indexnow mounts at/__router_index. Duplicate or unknown field initialisers, reserved names, and unsupported route arguments generate diagnostics. Previously discarded attributes now take effect.Behavioural Compatibility
Validation
The test and Clippy matrix passed on macOS with Rust 1.95.0, using both the existing lockfiles and fresh dependency resolution:
Workspace and consumer formatting and
just checkfcpassed using nightly. Documentation built with warnings denied using Rust 1.95.0.After the version updates, all 90 default-configuration tests passed again, and Cargo packaged and verified both release versions. Linux CI also passed formatting and the full test and Clippy matrix for both the push and pull request runs. Neither crate has been published.