feat(templated_uri): add try_effective_port method#451
Conversation
Adds a fallible variant of effective_port on Origin and BaseUri that returns a UriError when the authority does not specify a port and the scheme has no well-known default known to this crate (http, https).
There was a problem hiding this comment.
Pull request overview
This PR adds a fallible “effective port” accessor to templated_uri so callers can get a Result<u16, UriError> instead of Option<u16> when the scheme has no default port known to the crate.
Changes:
- Added
Origin::try_effective_port()returning an error when the port can’t be inferred. - Added
BaseUri::try_effective_port()delegating toOrigin. - Added tests and doc examples for the new APIs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/templated_uri/src/origin.rs | Adds Origin::try_effective_port() and tests covering explicit ports, http/https defaults, and unknown-scheme error behavior. |
| crates/templated_uri/src/base_uri.rs | Adds BaseUri::try_effective_port() and tests for success cases (explicit/http/https default). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #451 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 305 305
Lines 23707 23741 +34
=======================================
+ Hits 23707 23741 +34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sgalkin
left a comment
There was a problem hiding this comment.
Please address both Copilot comment - remove crate:: from UriError and add negative test case
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Adds a fallible variant of effective_port on Origin and BaseUri that returns a UriError when the authority does not specify a port and the scheme has no well-known default known to this crate (http, https).
(noticed that this could be useful when using the effective_port in our codebase)