diff options
Diffstat (limited to 'SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs')
| -rw-r--r-- | SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs b/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs index 34b5eaf74..7b4b619e6 100644 --- a/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs +++ b/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; -using System.Text; using System.Globalization; +using System.Text; namespace SocketHttpListener.Net { @@ -28,11 +28,11 @@ namespace SocketHttpListener.Net // The raw path is parsed by looping through all characters from left to right. 'rawOctets' // is used to store consecutive percent encoded octets as actual byte values: e.g. for path /pa%C3%84th%2F/ // rawOctets will be set to { 0xC3, 0x84 } when we reach character 't' and it will be { 0x2F } when - // we reach the final '/'. I.e. after a sequence of percent encoded octets ends, we use rawOctets as + // we reach the final '/'. I.e. after a sequence of percent encoded octets ends, we use rawOctets as // input to the encoding and percent encode the resulting string into UTF-8 octets. // // When parsing ANSI (Latin 1) encoded path '/pa%C4th/', %C4 will be added to rawOctets and when - // we reach 't', the content of rawOctets { 0xC4 } will be fed into the ANSI encoding. The resulting + // we reach 't', the content of rawOctets { 0xC4 } will be fed into the ANSI encoding. The resulting // string 'Ä' will be percent encoded into UTF-8 octets and appended to requestUriString. The final // path will be '/pa%C3%84th/', where '%C3%84' is the UTF-8 percent encoded character 'Ä'. private List<byte> _rawOctets; @@ -54,7 +54,7 @@ namespace SocketHttpListener.Net public static Uri GetRequestUri(string rawUri, string cookedUriScheme, string cookedUriHost, string cookedUriPath, string cookedUriQuery) { - HttpListenerRequestUriBuilder builder = new HttpListenerRequestUriBuilder(rawUri, + var builder = new HttpListenerRequestUriBuilder(rawUri, cookedUriScheme, cookedUriHost, cookedUriPath, cookedUriQuery); return builder.Build(); @@ -146,7 +146,7 @@ namespace SocketHttpListener.Net if (!Uri.TryCreate(_requestUriString.ToString(), UriKind.Absolute, out _requestUri)) { - // If we can't create a Uri from the string, this is an invalid string and it doesn't make + // If we can't create a Uri from the string, this is an invalid string and it doesn't make // sense to try another encoding. result = ParsingResult.InvalidString; } @@ -196,7 +196,7 @@ namespace SocketHttpListener.Net } else { - // We found '%', but not followed by 'u', i.e. we have a percent encoded octed: %XX + // We found '%', but not followed by 'u', i.e. we have a percent encoded octed: %XX if (!AddPercentEncodedOctetToRawOctetsList(encoding, _rawPath.Substring(index, 2))) { return ParsingResult.InvalidString; @@ -207,7 +207,7 @@ namespace SocketHttpListener.Net else { // We found a non-'%' character: decode the content of rawOctets into percent encoded - // UTF-8 characters and append it to the result. + // UTF-8 characters and append it to the result. if (!EmptyDecodeAndAppendRawOctetsList(encoding)) { return ParsingResult.EncodingError; @@ -232,8 +232,7 @@ namespace SocketHttpListener.Net { // http.sys only supports %uXXXX (4 hex-digits), even though unicode code points could have up to // 6 hex digits. Therefore we parse always 4 characters after %u and convert them to an int. - int codePointValue; - if (!int.TryParse(codePoint, NumberStyles.HexNumber, null, out codePointValue)) + if (!int.TryParse(codePoint, NumberStyles.HexNumber, null, out var codePointValue)) { //if (NetEventSource.IsEnabled) // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, codePoint)); @@ -264,8 +263,7 @@ namespace SocketHttpListener.Net private bool AddPercentEncodedOctetToRawOctetsList(Encoding encoding, string escapedCharacter) { - byte encodedValue; - if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out encodedValue)) + if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out byte encodedValue)) { //if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, escapedCharacter)); return false; @@ -327,7 +325,7 @@ namespace SocketHttpListener.Net private static string GetOctetsAsString(IEnumerable<byte> octets) { - StringBuilder octetString = new StringBuilder(); + var octetString = new StringBuilder(); bool first = true; foreach (byte octet in octets) @@ -402,7 +400,7 @@ namespace SocketHttpListener.Net // Find end of path: The path is terminated by // - the first '?' character - // - the first '#' character: This is never the case here, since http.sys won't accept + // - the first '#' character: This is never the case here, since http.sys won't accept // Uris containing fragments. Also, RFC2616 doesn't allow fragments in request Uris. // - end of Uri string int queryIndex = uriString.IndexOf('?'); |
