Skip to content

Commit

Permalink
Use IndexOfAny in HttpListener.HandleAuthentication (#71137)
Browse files Browse the repository at this point in the history
* Use IndexOfAny in HttpListener.HandleAuthentication

Just cleaning up a manual loop that can instead be IndexOfAny.

* Fix missing check
  • Loading branch information
stephentoub committed Jun 23, 2022
1 parent 70e9ca0 commit 982946a
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,10 @@ public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
if (authorizationHeader != null && (authenticationScheme & ~AuthenticationSchemes.Anonymous) != AuthenticationSchemes.None)
{
// Find the end of the scheme name. Trust that HTTP.SYS parsed out just our header ok.
for (index = 0; index < authorizationHeader.Length; index++)
index = authorizationHeader.AsSpan().IndexOfAny(" \t\r\n");
if (index < 0)
{
if (authorizationHeader[index] == ' ' || authorizationHeader[index] == '\t' ||
authorizationHeader[index] == '\r' || authorizationHeader[index] == '\n')
{
break;
}
index = authorizationHeader.Length;
}

// Currently only allow one Authorization scheme/header per request.
Expand Down

0 comments on commit 982946a

Please sign in to comment.