diff options
| author | LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com> | 2019-01-23 00:31:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-23 00:31:35 -0800 |
| commit | 404bd04cbc17dc8c8bf4a5c9aa3ca9c5cd85aa68 (patch) | |
| tree | 3d267c6ceef9439a034c113095e10e4d619e7c70 /RSSDP/HttpRequestParser.cs | |
| parent | 8ff89fdc0c30f595a171ffc550f907ef22b6212a (diff) | |
| parent | e05e002b8bb4d13eb2b80b56a0aad8903ddb701e (diff) | |
Merge pull request #8 from jellyfin/master
rebase to latest master
Diffstat (limited to 'RSSDP/HttpRequestParser.cs')
| -rw-r--r-- | RSSDP/HttpRequestParser.cs | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.cs index 8460e1ca5..d4505b8ad 100644 --- a/RSSDP/HttpRequestParser.cs +++ b/RSSDP/HttpRequestParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -8,70 +8,70 @@ using System.Threading.Tasks; namespace Rssdp.Infrastructure { - /// <summary> - /// Parses a string into a <see cref="System.Net.Http.HttpRequestMessage"/> or throws an exception. - /// </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 - - /// <summary> - /// Parses the specified data into a <see cref="System.Net.Http.HttpRequestMessage"/> instance. - /// </summary> - /// <param name="data">A string containing the data to parse.</param> - /// <returns>A <see cref="System.Net.Http.HttpRequestMessage"/> instance containing the parsed data.</returns> - public override System.Net.Http.HttpRequestMessage Parse(string data) - { - System.Net.Http.HttpRequestMessage retVal = null; - - try - { - retVal = new System.Net.Http.HttpRequestMessage(); - - Parse(retVal, retVal.Headers, data); - - return retVal; - } - 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> - /// <param name="data">The first line of the HTTP message to be parsed.</param> - /// <param name="message">Either a <see cref="System.Net.Http.HttpResponseMessage"/> or <see cref="System.Net.Http.HttpRequestMessage"/> to assign the parsed values to.</param> - protected override void ParseStatusLine(string data, HttpRequestMessage message) - { - if (data == null) throw new ArgumentNullException("data"); - if (message == null) throw new ArgumentNullException("message"); - - var parts = data.Split(' '); - if (parts.Length < 2) throw new ArgumentException("Status line is invalid. Insufficient status parts.", "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]); + /// <summary> + /// Parses a string into a <see cref="HttpRequestMessage"/> or throws an exception. + /// </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 + + /// <summary> + /// Parses the specified data into a <see cref="HttpRequestMessage"/> instance. + /// </summary> + /// <param name="data">A string containing the data to parse.</param> + /// <returns>A <see cref="HttpRequestMessage"/> instance containing the parsed data.</returns> + public override HttpRequestMessage Parse(string data) + { + HttpRequestMessage retVal = null; + + try + { + retVal = new HttpRequestMessage(); + + Parse(retVal, retVal.Headers, data); + + return retVal; + } + 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> + /// <param name="data">The first line of the HTTP message to be parsed.</param> + /// <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)); + + var parts = data.Split(' '); + 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) { @@ -79,16 +79,16 @@ namespace Rssdp.Infrastructure } } - /// <summary> - /// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false). - /// </summary> - /// <param name="headerName">A string containing the name of the header to return the type of.</param> - protected override bool IsContentHeader(string headerName) - { - return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); - } + /// <summary> + /// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false). + /// </summary> + /// <param name="headerName">A string containing the name of the header to return the type of.</param> + protected override bool IsContentHeader(string headerName) + { + return ContentHeaderNames.Contains(headerName, StringComparer.OrdinalIgnoreCase); + } - #endregion + #endregion - } -}
\ No newline at end of file + } +} |
