diff options
| author | Nyanmisaka <nst799610810@gmail.com> | 2020-06-25 16:37:40 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-25 16:37:40 +0800 |
| commit | 912946a42793305ecdc6a8c176f1775ffe7ac0de (patch) | |
| tree | 6a4d85c4869ed8cb5d15f3fa8c82512de6405b6e /RSSDP/HttpRequestParser.cs | |
| parent | bfd87829e3bca42a245287b99e652d091b21c990 (diff) | |
| parent | 91c51ae6752720d6272e6a0c651edd3780e150ac (diff) | |
Merge pull request from jellyfin/master
Diffstat (limited to 'RSSDP/HttpRequestParser.cs')
| -rw-r--r-- | RSSDP/HttpRequestParser.cs | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.cs index 279ef883c..4114195a6 100644 --- a/RSSDP/HttpRequestParser.cs +++ b/RSSDP/HttpRequestParser.cs @@ -9,17 +9,10 @@ namespace Rssdp.Infrastructure /// </summary> public sealed class HttpRequestParser : HttpParserBase<HttpRequestMessage> { - - #region Fields & Constants - private readonly string[] ContentHeaderNames = new string[] - { - "Allow", "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Expires", "Last-Modified" - }; - - #endregion - - #region Public Methods + { + "Allow", "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Expires", "Last-Modified" + }; /// <summary> /// Parses the specified data into a <see cref="HttpRequestMessage"/> instance. @@ -41,14 +34,12 @@ namespace Rssdp.Infrastructure finally { if (retVal != null) + { retVal.Dispose(); + } } } - #endregion - - #region Overrides - /// <summary> /// Used to parse the first line of an HTTP request or response and assign the values to the appropriate properties on the <paramref name="message"/>. /// </summary> @@ -56,18 +47,32 @@ namespace Rssdp.Infrastructure /// <param name="message">Either a <see cref="HttpResponseMessage"/> or <see cref="HttpRequestMessage"/> to assign the parsed values to.</param> protected override void ParseStatusLine(string data, HttpRequestMessage message) { - if (data == null) throw new ArgumentNullException(nameof(data)); - if (message == null) throw new ArgumentNullException(nameof(message)); + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + + if (message == null) + { + throw new ArgumentNullException(nameof(message)); + } var parts = data.Split(' '); - if (parts.Length < 2) throw new ArgumentException("Status line is invalid. Insufficient status parts.", nameof(data)); + if (parts.Length < 2) + { + throw new ArgumentException("Status line is invalid. Insufficient status parts.", nameof(data)); + } message.Method = new HttpMethod(parts[0].Trim()); Uri requestUri; if (Uri.TryCreate(parts[1].Trim(), UriKind.RelativeOrAbsolute, out requestUri)) + { message.RequestUri = requestUri; + } else + { System.Diagnostics.Debug.WriteLine(parts[1]); + } if (parts.Length >= 3) { @@ -83,8 +88,5 @@ namespace Rssdp.Infrastructure { return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); } - - #endregion - } } |
