aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/HttpServer
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2019-01-16 19:10:42 +0100
committerGitHub <noreply@github.com>2019-01-16 19:10:42 +0100
commit900dc851e6c810f9e1772a6fb901a5a7e2801baf (patch)
tree205bac3cd6df971ee18739e59bd4da0ffe91718b /Emby.Server.Implementations/HttpServer
parent07a8e49c4b1e4a2dddbaa49ab6f1ff4f271fbf20 (diff)
parent933ef438894ed233fec46badf58dd4f26492e832 (diff)
Merge branch 'dev' into cleanup
Diffstat (limited to 'Emby.Server.Implementations/HttpServer')
-rw-r--r--Emby.Server.Implementations/HttpServer/FileWriter.cs13
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs25
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpResultFactory.cs26
-rw-r--r--Emby.Server.Implementations/HttpServer/IHttpListener.cs2
-rw-r--r--Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs15
-rw-r--r--Emby.Server.Implementations/HttpServer/Security/AuthService.cs6
-rw-r--r--Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs6
-rw-r--r--Emby.Server.Implementations/HttpServer/StreamWriter.cs9
-rw-r--r--Emby.Server.Implementations/HttpServer/WebSocketConnection.cs22
9 files changed, 56 insertions, 68 deletions
diff --git a/Emby.Server.Implementations/HttpServer/FileWriter.cs b/Emby.Server.Implementations/HttpServer/FileWriter.cs
index 1a875e533..568432902 100644
--- a/Emby.Server.Implementations/HttpServer/FileWriter.cs
+++ b/Emby.Server.Implementations/HttpServer/FileWriter.cs
@@ -38,10 +38,7 @@ namespace Emby.Server.Implementations.HttpServer
/// Gets the options.
/// </summary>
/// <value>The options.</value>
- public IDictionary<string, string> Headers
- {
- get { return _options; }
- }
+ public IDictionary<string, string> Headers => _options;
public string Path { get; set; }
@@ -49,7 +46,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (string.IsNullOrEmpty(contentType))
{
- throw new ArgumentNullException("contentType");
+ throw new ArgumentNullException(nameof(contentType));
}
Path = path;
@@ -148,7 +145,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- private string[] SkipLogExtensions = new string[]
+ private string[] SkipLogExtensions = new string[]
{
".js",
".html",
@@ -203,8 +200,8 @@ namespace Emby.Server.Implementations.HttpServer
public HttpStatusCode StatusCode
{
- get { return (HttpStatusCode)Status; }
- set { Status = (int)value; }
+ get => (HttpStatusCode)Status;
+ set => Status = (int)value;
}
public string StatusDescription { get; set; }
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index 91b2e9ded..fb5f53367 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -1,4 +1,3 @@
-
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -13,7 +12,6 @@ using Emby.Server.Implementations.Net;
using Emby.Server.Implementations.Services;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
-using MediaBrowser.Common.Security;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
@@ -97,7 +95,7 @@ namespace Emby.Server.Implementations.HttpServer
}
/// <summary>
- /// Applies the request filters. Returns whether or not the request has been handled
+ /// Applies the request filters. Returns whether or not the request has been handled
/// and no more processing should be done.
/// </summary>
/// <returns></returns>
@@ -181,7 +179,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- private Exception GetActualException(Exception ex)
+ private static Exception GetActualException(Exception ex)
{
if (ex is AggregateException agg)
{
@@ -209,7 +207,6 @@ namespace Emby.Server.Implementations.HttpServer
{
case ArgumentException _: return 400;
case SecurityException _: return 401;
- case PaymentRequiredException _: return 402;
case DirectoryNotFoundException _:
case FileNotFoundException _:
case ResourceNotFoundException _: return 404;
@@ -319,7 +316,7 @@ namespace Emby.Server.Implementations.HttpServer
&& (string.IsNullOrEmpty(localPath) || localPath.IndexOf("system/ping", StringComparison.OrdinalIgnoreCase) == -1));
}
- private string GetExtension(string url)
+ private static string GetExtension(string url)
{
var parts = url.Split(new[] { '?' }, 2);
@@ -352,18 +349,18 @@ namespace Emby.Server.Implementations.HttpServer
string pagePathWithoutQueryString = url.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];
return newQueryString.Count > 0
- ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
+ ? string.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
: pagePathWithoutQueryString;
}
- private string GetUrlToLog(string url)
+ private static string GetUrlToLog(string url)
{
url = RemoveQueryStringByKey(url, "api_key");
return url;
}
- private string NormalizeConfiguredLocalAddress(string address)
+ private static string NormalizeConfiguredLocalAddress(string address)
{
var index = address.Trim('/').IndexOf('/');
@@ -698,7 +695,7 @@ namespace Emby.Server.Implementations.HttpServer
return null;
}
- private Task Write(IResponse response, string text)
+ private static Task Write(IResponse response, string text)
{
var bOutput = Encoding.UTF8.GetBytes(text);
response.SetContentLength(bOutput.Length);
@@ -817,7 +814,9 @@ namespace Emby.Server.Implementations.HttpServer
return _jsonSerializer.DeserializeFromStreamAsync(stream, type);
}
- private string NormalizeEmbyRoutePath(string path)
+ //TODO Add Jellyfin Route Path Normalizer
+
+ private static string NormalizeEmbyRoutePath(string path)
{
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
{
@@ -827,7 +826,7 @@ namespace Emby.Server.Implementations.HttpServer
return "emby/" + path;
}
- private string NormalizeMediaBrowserRoutePath(string path)
+ private static string NormalizeMediaBrowserRoutePath(string path)
{
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
{
@@ -837,7 +836,7 @@ namespace Emby.Server.Implementations.HttpServer
return "mediabrowser/" + path;
}
- private string DoubleNormalizeEmbyRoutePath(string path)
+ private static string DoubleNormalizeEmbyRoutePath(string path)
{
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
{
diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
index 3d0fb577a..bacf5556f 100644
--- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
@@ -1,4 +1,4 @@
-using MediaBrowser.Common.Extensions;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Net;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
@@ -207,7 +207,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (result == null)
{
- throw new ArgumentNullException("result");
+ throw new ArgumentNullException(nameof(result));
}
if (responseHeaders == null)
@@ -245,7 +245,7 @@ namespace Emby.Server.Implementations.HttpServer
return GetCompressionType(request);
}
- private string GetCompressionType(IRequest request)
+ private static string GetCompressionType(IRequest request)
{
var acceptEncoding = request.Headers["Accept-Encoding"];
@@ -265,7 +265,7 @@ namespace Emby.Server.Implementations.HttpServer
}
/// <summary>
- /// Returns the optimized result for the IRequestContext.
+ /// Returns the optimized result for the IRequestContext.
/// Does not use or store results in any cache.
/// </summary>
/// <param name="request"></param>
@@ -365,7 +365,7 @@ namespace Emby.Server.Implementations.HttpServer
return _brotliCompressor.Compress(bytes);
}
- private byte[] Deflate(byte[] bytes)
+ private static byte[] Deflate(byte[] bytes)
{
// In .NET FX incompat-ville, you can't access compressed bytes without closing DeflateStream
// Which means we must use MemoryStream since you have to use ToArray() on a closed Stream
@@ -379,7 +379,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- private byte[] GZip(byte[] buffer)
+ private static byte[] GZip(byte[] buffer)
{
using (var ms = new MemoryStream())
using (var zipStream = new GZipStream(ms, CompressionMode.Compress))
@@ -398,7 +398,7 @@ namespace Emby.Server.Implementations.HttpServer
: contentType.Split(';')[0].ToLower().Trim();
}
- private string SerializeToXmlString(object from)
+ private static string SerializeToXmlString(object from)
{
using (var ms = new MemoryStream())
{
@@ -455,7 +455,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (string.IsNullOrEmpty(path))
{
- throw new ArgumentNullException("path");
+ throw new ArgumentNullException(nameof(path));
}
return GetStaticFileResult(requestContext, new StaticFileResultOptions
@@ -472,7 +472,7 @@ namespace Emby.Server.Implementations.HttpServer
if (string.IsNullOrEmpty(path))
{
- throw new ArgumentNullException("path");
+ throw new ArgumentNullException(nameof(path));
}
if (fileShare != FileShareMode.Read && fileShare != FileShareMode.ReadWrite)
@@ -662,7 +662,7 @@ namespace Emby.Server.Implementations.HttpServer
/// <summary>
/// Adds the expires header.
/// </summary>
- private void AddExpiresHeader(IDictionary<string, string> responseHeaders, string cacheKey, TimeSpan? cacheDuration)
+ private static void AddExpiresHeader(IDictionary<string, string> responseHeaders, string cacheKey, TimeSpan? cacheDuration)
{
if (cacheDuration.HasValue)
{
@@ -679,7 +679,7 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
/// <param name="responseHeaders">The responseHeaders.</param>
/// <param name="lastDateModified">The last date modified.</param>
- private void AddAgeHeader(IDictionary<string, string> responseHeaders, DateTime? lastDateModified)
+ private static void AddAgeHeader(IDictionary<string, string> responseHeaders, DateTime? lastDateModified)
{
if (lastDateModified.HasValue)
{
@@ -762,7 +762,7 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
/// <param name="date">The date.</param>
/// <returns>DateTime.</returns>
- private DateTime NormalizeDateForComparison(DateTime date)
+ private static DateTime NormalizeDateForComparison(DateTime date)
{
return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind);
}
@@ -772,7 +772,7 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
/// <param name="hasHeaders">The has options.</param>
/// <param name="responseHeaders">The response headers.</param>
- private void AddResponseHeaders(IHasHeaders hasHeaders, IEnumerable<KeyValuePair<string, string>> responseHeaders)
+ private static void AddResponseHeaders(IHasHeaders hasHeaders, IEnumerable<KeyValuePair<string, string>> responseHeaders)
{
foreach (var item in responseHeaders)
{
diff --git a/Emby.Server.Implementations/HttpServer/IHttpListener.cs b/Emby.Server.Implementations/HttpServer/IHttpListener.cs
index e21607ebd..d50d7df6b 100644
--- a/Emby.Server.Implementations/HttpServer/IHttpListener.cs
+++ b/Emby.Server.Implementations/HttpServer/IHttpListener.cs
@@ -33,7 +33,7 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
/// <value>The web socket connecting.</value>
Action<WebSocketConnectingEventArgs> WebSocketConnecting { get; set; }
-
+
/// <summary>
/// Starts this instance.
/// </summary>
diff --git a/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs b/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs
index 795f96f2c..ef47a7ca9 100644
--- a/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs
+++ b/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs
@@ -1,4 +1,4 @@
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -44,10 +44,7 @@ namespace Emby.Server.Implementations.HttpServer
/// Additional HTTP Headers
/// </summary>
/// <value>The headers.</value>
- public IDictionary<string, string> Headers
- {
- get { return _options; }
- }
+ public IDictionary<string, string> Headers => _options;
/// <summary>
/// Initializes a new instance of the <see cref="StreamWriter" /> class.
@@ -60,7 +57,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (string.IsNullOrEmpty(contentType))
{
- throw new ArgumentNullException("contentType");
+ throw new ArgumentNullException(nameof(contentType));
}
RangeHeader = rangeHeader;
@@ -183,7 +180,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- private async Task CopyToInternalAsync(Stream source, Stream destination, long copyLength)
+ private static async Task CopyToInternalAsync(Stream source, Stream destination, long copyLength)
{
var array = new byte[BufferSize];
int bytesRead;
@@ -217,8 +214,8 @@ namespace Emby.Server.Implementations.HttpServer
public HttpStatusCode StatusCode
{
- get { return (HttpStatusCode)Status; }
- set { Status = (int)value; }
+ get => (HttpStatusCode)Status;
+ set => Status = (int)value;
}
}
}
diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs
index e153d6f71..fb5bfa601 100644
--- a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs
+++ b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs
@@ -1,4 +1,4 @@
-using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Entities;
@@ -173,7 +173,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
return false;
}
- private void ValidateRoles(string[] roles, User user)
+ private static void ValidateRoles(string[] roles, User user)
{
if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase))
{
@@ -207,7 +207,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
}
}
- private AuthenticationInfo GetTokenInfo(IRequest request)
+ private static AuthenticationInfo GetTokenInfo(IRequest request)
{
object info;
request.Items.TryGetValue("OriginalAuthenticationInfo", out info);
diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs b/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs
index c3e2d3170..f561c3d60 100644
--- a/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs
+++ b/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs
@@ -1,4 +1,4 @@
-using MediaBrowser.Controller.Connect;
+using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security;
using System;
@@ -115,7 +115,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
{
info.Device = tokenInfo.DeviceName;
}
-
+
else if (!string.Equals(info.Device, tokenInfo.DeviceName, StringComparison.OrdinalIgnoreCase))
{
if (allowTokenInfoUpdate)
@@ -227,7 +227,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
return result;
}
- private string NormalizeValue(string value)
+ private static string NormalizeValue(string value)
{
if (string.IsNullOrEmpty(value))
{
diff --git a/Emby.Server.Implementations/HttpServer/StreamWriter.cs b/Emby.Server.Implementations/HttpServer/StreamWriter.cs
index 0a44a5fe5..df0d74685 100644
--- a/Emby.Server.Implementations/HttpServer/StreamWriter.cs
+++ b/Emby.Server.Implementations/HttpServer/StreamWriter.cs
@@ -35,10 +35,7 @@ namespace Emby.Server.Implementations.HttpServer
/// Gets the options.
/// </summary>
/// <value>The options.</value>
- public IDictionary<string, string> Headers
- {
- get { return _options; }
- }
+ public IDictionary<string, string> Headers => _options;
public Action OnComplete { get; set; }
public Action OnError { get; set; }
@@ -53,7 +50,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (string.IsNullOrEmpty(contentType))
{
- throw new ArgumentNullException("contentType");
+ throw new ArgumentNullException(nameof(contentType));
}
SourceStream = source;
@@ -77,7 +74,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (string.IsNullOrEmpty(contentType))
{
- throw new ArgumentNullException("contentType");
+ throw new ArgumentNullException(nameof(contentType));
}
SourceBytes = source;
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
index 914fa9dbc..5426114f6 100644
--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
@@ -82,19 +82,19 @@ namespace Emby.Server.Implementations.HttpServer
{
if (socket == null)
{
- throw new ArgumentNullException("socket");
+ throw new ArgumentNullException(nameof(socket));
}
if (string.IsNullOrEmpty(remoteEndPoint))
{
- throw new ArgumentNullException("remoteEndPoint");
+ throw new ArgumentNullException(nameof(remoteEndPoint));
}
if (jsonSerializer == null)
{
- throw new ArgumentNullException("jsonSerializer");
+ throw new ArgumentNullException(nameof(jsonSerializer));
}
if (logger == null)
{
- throw new ArgumentNullException("logger");
+ throw new ArgumentNullException(nameof(logger));
}
Id = Guid.NewGuid();
@@ -148,7 +148,8 @@ namespace Emby.Server.Implementations.HttpServer
/// <summary>
/// Called when [receive].
/// </summary>
- /// <param name="bytes">The bytes.</param>
+ /// <param name="memory">The memory block.</param>
+ /// <param name="length">The length of the memory block.</param>
private void OnReceiveInternal(Memory<byte> memory, int length)
{
LastActivityDate = DateTime.UtcNow;
@@ -219,7 +220,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (message == null)
{
- throw new ArgumentNullException("message");
+ throw new ArgumentNullException(nameof(message));
}
var json = _jsonSerializer.SerializeToString(message);
@@ -237,7 +238,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (buffer == null)
{
- throw new ArgumentNullException("buffer");
+ throw new ArgumentNullException(nameof(buffer));
}
cancellationToken.ThrowIfCancellationRequested();
@@ -249,7 +250,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (string.IsNullOrEmpty(text))
{
- throw new ArgumentNullException("text");
+ throw new ArgumentNullException(nameof(text));
}
cancellationToken.ThrowIfCancellationRequested();
@@ -261,10 +262,7 @@ namespace Emby.Server.Implementations.HttpServer
/// Gets the state.
/// </summary>
/// <value>The state.</value>
- public WebSocketState State
- {
- get { return _socket.State; }
- }
+ public WebSocketState State => _socket.State;
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.