aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2019-06-01 17:06:01 +0200
committerGitHub <noreply@github.com>2019-06-01 17:06:01 +0200
commitce1fa42f9d39add8467bfed186730c4a9545344d (patch)
tree8c2aafa3a3552174d15208551da1c34449a13b18 /Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
parent2696ac5eacfb4702d629bc06a8b42b868c316116 (diff)
parentb1f764984f7098ee1164efee77f1bcb3de9fd08a (diff)
Merge branch 'master' into tasks
Diffstat (limited to 'Emby.Server.Implementations/HttpServer/HttpListenerHost.cs')
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs51
1 files changed, 17 insertions, 34 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index 9214f2afe..d8938964f 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Sockets;
@@ -126,12 +125,12 @@ namespace Emby.Server.Implementations.HttpServer
private List<IHasRequestFilter> GetRequestFilterAttributes(Type requestDtoType)
{
- var attributes = requestDtoType.GetTypeInfo().GetCustomAttributes(true).OfType<IHasRequestFilter>().ToList();
+ var attributes = requestDtoType.GetCustomAttributes(true).OfType<IHasRequestFilter>().ToList();
var serviceType = GetServiceTypeByRequest(requestDtoType);
if (serviceType != null)
{
- attributes.AddRange(serviceType.GetTypeInfo().GetCustomAttributes(true).OfType<IHasRequestFilter>());
+ attributes.AddRange(serviceType.GetCustomAttributes(true).OfType<IHasRequestFilter>());
}
attributes.Sort((x, y) => x.Priority - y.Priority);
@@ -153,7 +152,7 @@ namespace Emby.Server.Implementations.HttpServer
QueryString = e.QueryString ?? new QueryCollection()
};
- connection.Closed += Connection_Closed;
+ connection.Closed += OnConnectionClosed;
lock (_webSocketConnections)
{
@@ -163,7 +162,7 @@ namespace Emby.Server.Implementations.HttpServer
WebSocketConnected?.Invoke(this, new GenericEventArgs<IWebSocketConnection>(connection));
}
- private void Connection_Closed(object sender, EventArgs e)
+ private void OnConnectionClosed(object sender, EventArgs e)
{
lock (_webSocketConnections)
{
@@ -202,6 +201,7 @@ namespace Emby.Server.Implementations.HttpServer
case DirectoryNotFoundException _:
case FileNotFoundException _:
case ResourceNotFoundException _: return 404;
+ case MethodNotAllowedException _: return 405;
case RemoteServiceUnavailableException _: return 502;
default: return 500;
}
@@ -321,14 +321,14 @@ namespace Emby.Server.Implementations.HttpServer
private static string NormalizeConfiguredLocalAddress(string address)
{
- var index = address.Trim('/').IndexOf('/');
-
+ var add = address.AsSpan().Trim('/');
+ int index = add.IndexOf('/');
if (index != -1)
{
- address = address.Substring(index + 1);
+ add = add.Slice(index + 1);
}
- return address.Trim('/');
+ return add.TrimStart('/').ToString();
}
private bool ValidateHost(string host)
@@ -398,8 +398,8 @@ namespace Emby.Server.Implementations.HttpServer
if (urlString.IndexOf("https://", StringComparison.OrdinalIgnoreCase) == -1)
{
// These are hacks, but if these ever occur on ipv6 in the local network they could be incorrectly redirected
- if (urlString.IndexOf("system/ping", StringComparison.OrdinalIgnoreCase) != -1 ||
- urlString.IndexOf("dlna/", StringComparison.OrdinalIgnoreCase) != -1)
+ if (urlString.IndexOf("system/ping", StringComparison.OrdinalIgnoreCase) != -1
+ || urlString.IndexOf("dlna/", StringComparison.OrdinalIgnoreCase) != -1)
{
return true;
}
@@ -571,7 +571,7 @@ namespace Emby.Server.Implementations.HttpServer
if (handler != null)
{
- await handler.ProcessRequestAsync(this, httpReq, httpRes, Logger, httpReq.OperationName, cancellationToken).ConfigureAwait(false);
+ await handler.ProcessRequestAsync(this, httpReq, httpRes, Logger, cancellationToken).ConfigureAwait(false);
}
else
{
@@ -612,21 +612,11 @@ namespace Emby.Server.Implementations.HttpServer
{
var pathInfo = httpReq.PathInfo;
- var pathParts = pathInfo.TrimStart('/').Split('/');
- if (pathParts.Length == 0)
- {
- Logger.LogError("Path parts empty for PathInfo: {PathInfo}, Url: {RawUrl}", pathInfo, httpReq.RawUrl);
- return null;
- }
-
- var restPath = ServiceHandler.FindMatchingRestPath(httpReq.HttpMethod, pathInfo, out string contentType);
+ pathInfo = ServiceHandler.GetSanitizedPathInfo(pathInfo, out string contentType);
+ var restPath = ServiceController.GetRestPathForRequest(httpReq.HttpMethod, pathInfo);
if (restPath != null)
{
- return new ServiceHandler
- {
- RestPath = restPath,
- ResponseContentType = contentType
- };
+ return new ServiceHandler(restPath, contentType);
}
Logger.LogError("Could not find handler for {PathInfo}", pathInfo);
@@ -636,6 +626,7 @@ namespace Emby.Server.Implementations.HttpServer
private static Task Write(IResponse response, string text)
{
var bOutput = Encoding.UTF8.GetBytes(text);
+ response.OriginalResponse.ContentLength = bOutput.Length;
return response.OutputStream.WriteAsync(bOutput, 0, bOutput.Length);
}
@@ -654,11 +645,6 @@ namespace Emby.Server.Implementations.HttpServer
}
else
{
- // TODO what is this?
- var httpsUrl = url
- .Replace("http://", "https://", StringComparison.OrdinalIgnoreCase)
- .Replace(":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture), ":" + _config.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase);
-
RedirectToUrl(httpRes, url);
}
}
@@ -683,10 +669,7 @@ namespace Emby.Server.Implementations.HttpServer
UrlPrefixes = urlPrefixes.ToArray();
ServiceController = new ServiceController();
- Logger.LogInformation("Calling ServiceStack AppHost.Init");
-
- var types = services.Select(r => r.GetType()).ToArray();
-
+ var types = services.Select(r => r.GetType());
ServiceController.Init(this, types);
ResponseFilters = new Action<IRequest, IResponse, object>[]