-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Remove redundant uri check in HttpListenerRequest #55683
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
Conversation
|
Tagging subscribers to this area: @dotnet/ncl Issue Details
|
| private static bool IsPredefinedScheme(ReadOnlySpan<char> scheme) | ||
| { | ||
| if (scheme == null || scheme.Length < 3) | ||
| if (scheme.Length < 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of the code below is now incorrect. All of the equality operators are going to do the wrong thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerRequest.Managed.cs
Lines 183 to 186 in 98c9f29
| if (MaybeUri(_rawUrl!.ToLowerInvariant()) && Uri.TryCreate(_rawUrl, UriKind.Absolute, out raw_uri)) | |
| path = raw_uri.PathAndQuery; | |
| else | |
| path = _rawUrl; |
I don't see how this is supposed to be better than just calling into Uri directly.
IMO the right optimization here would be to remove the MaybeUri entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean just to remove MaybeUri(_rawUrl!.ToLowerInvariant()) &&? (And the MaybeUri body)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is the exact same logic that is called in Uri.TryCreate
runtime/src/libraries/System.Private.Uri/src/System/Uri.cs
Lines 3573 to 3585 in dfd618d
| private static unsafe bool CheckKnownSchemes(long* lptr, int nChars, ref UriParser? syntax) | |
| { | |
| //NOTE beware of too short input buffers! | |
| const long _HTTP_Mask0 = 'h' | ('t' << 16) | ((long)'t' << 32) | ((long)'p' << 48); | |
| const char _HTTPS_Mask1 = 's'; | |
| const int _WS_Mask = 'w' | ('s' << 16); | |
| const long _WSS_Mask = 'w' | ('s' << 16) | ((long)'s' << 32) | ((long)':' << 48); | |
| const long _FTP_Mask = 'f' | ('t' << 16) | ((long)'p' << 32) | ((long)':' << 48); | |
| const long _FILE_Mask0 = 'f' | ('i' << 16) | ((long)'l' << 32) | ((long)'e' << 48); | |
| const long _GOPHER_Mask0 = 'g' | ('o' << 16) | ((long)'p' << 32) | ((long)'h' << 48); | |
| const int _GOPHER_Mask1 = 'e' | ('r' << 16); | |
| const long _MAILTO_Mask0 = 'm' | ('a' << 16) | ((long)'i' << 32) | ((long)'l' << 48); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean just to remove MaybeUri(_rawUrl!.ToLowerInvariant()) &&? (And the MaybeUri body)
Yes, if Uri.TryCreate isn't able to perform well here, it should be improved instead. Duplicating such logic makes no sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the failures may be due to the fact Uri accepts implicit file Uris as "absolute", so just the path may be accepted as absolute.
Could be mitigated by replacing MaybeUri with StartsWith("http", OrdinalIgnoreCase) or just reverting the change.
|
😢 UPD: Oh, yes, it works 😄 |
|
Http3_MsQuic test failures are tracked in #56090. Should be fixed and merged shortly. Sorry for the inconvenience! |
No description provided.