-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for more default ports in Uri
class
#51163
Comments
Uri
classUri
class
We try not to have to recognize too may schemes, currently just It's easy to add more default ports, but I don't want to have to support any other special-cases of other schemes (like special canonicalization rules or path resolution rules). They'd have to be completely standard hierarchical URIs with normal host names and ports. So, which that in mind, which schemes do you propose to add default ports for? From a quick glance, In practice, I'd probably just support |
Thank you, @irhn, for the quick response and your explanations!
My use-cache is probably a bit niche and concerns CoAP (RFC 7252), a web transfer protocol for IoT scenarios and the interaction with constrained devices, which is quite similar to HTTP, but more resource-efficient. If I see it correctly, in order to support CoAP and its different URI schemes, adding the default ports would be sufficient (see section 6 of RFC 7252 for more information). However, I could understand if you want to focus on more commonly used protocols to keep things as maintainable as possible. Edit: Then again, this addition would probably cause little to no additional maintenance effort in the future due to the close alignment of CoAP with HTTP.
In any case, adding additional support for these two URI schemes sounds great :) |
I created #51203 (https://dart-review.googlesource.com/c/sdk/+/280215) with an initial proposal which could be used for further discussing this issue. |
The implementation looks fine. My main worry is that it feels arbitrary. Why these? What is the protocol for adding more in the future? A platform library is not the best place to place large swathes of data that is almost never used. Should we instead give user code a way to add default ports, so you can add That's what we have considered doing for |
Thank you for the feedback, @lrhn!
I understand your concern. I'd say if support for more default URI ports would be added to the core library, then new ports should be requested via an issue, and limited to those registered in the IANA registry that do not require additional handling in the
That would be a very good alternative! |
Hmm, would you be fine with the PR/CL if this policy was followed for future additions? Or would you rather prefer closing/adapting it to a subset of the proposed schemes and introducing an extension mechanism instead? |
I'd probably prefer an extension mechanism only. Keeping up with an living external definition is a Sisyphos task (q.v., Unicode), and having a policy where others can request updates is just adding more work for people who have no personal interest in the result. Which means I'd lean towards adding a method like The biggest issue with that is that the call need to happen before anyone calls We can even choose to cache the input, and update the global tables, the first time we see a map argument to one of those functions. |
You're right about that. The extension mechanism you've proposed sounds good and would also cover my use-case. Should we close #51203 (and the associated CL) then? Or would some ports (e.g. those for WebSockets) still make sense to add?
Adding an
Hmm, would you say that all consecutive calls should then be ignored? Or should an exception be thrown if an already registered scheme is re-registered to a different port? In any case, I think it would be nice if you had the flexibility to integrate additional protocol support via dedicated libraries that can each register their needed URI ports independently (e.g., the first time a respective protocol client is created). |
I now updated #51203 (and the corresponding CL) to only add default ports for |
I think this addition is general and valuable enough, so let's go ahead! |
Turns out it broke some tests which used A default port is removed from the (Everything is breaking! Changes are hard. Let's go shopping.) |
That is unfortunate, but probably not unexpected :/ Should we abandon this endeavor then (and maybe turn to the solution for passing additional default ports instead)? Or could this breaking change be a part of Dart 3? |
Not planning on any (further) breaking changes for Dart 3.0. The ones we do add are mostly language based, which means they are language versioned and won't affect code until it upgrades to using the 3.0 language. It's probably safer to just add the configuration option. I'll consider how to do that (but with lower priority than the 3.0-related library changes). |
The
Uri
class currently only supports the default ports for thehttp
andhttps
schemes:sdk/sdk/lib/core/uri.dart
Lines 1718 to 1723 in 50b94ef
For a library I am contributing to, it would be handy if more URI schemes could be added here. Would you be fine with turning the checks in this method into a switch statement with the possibility to add more URI schemes? If so, I would open a PR/hand in a patch with an initial proposal.
The text was updated successfully, but these errors were encountered: