Last bits

This commit is contained in:
Bond_009 2019-02-09 12:01:11 +01:00 committed by Bond-009
parent 8d98885cda
commit 585b5201f1

View File

@ -27,30 +27,6 @@ namespace Jellyfin.Server.SocketSharp
//HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]); //HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]);
} }
private static string GetHandlerPathIfAny(string listenerUrl)
{
if (listenerUrl == null)
{
return null;
}
var pos = listenerUrl.IndexOf("://", StringComparison.OrdinalIgnoreCase);
if (pos == -1)
{
return null;
}
var startHostUrl = listenerUrl.Substring(pos + "://".Length);
var endPos = startHostUrl.IndexOf('/');
if (endPos == -1)
{
return null;
}
var endHostUrl = startHostUrl.Substring(endPos + 1);
return string.IsNullOrEmpty(endHostUrl) ? null : endHostUrl.TrimEnd('/');
}
public HttpListenerRequest HttpRequest => request; public HttpListenerRequest HttpRequest => request;
public object OriginalRequest => request; public object OriginalRequest => request;
@ -216,6 +192,8 @@ namespace Jellyfin.Server.SocketSharp
{ {
foreach (var acceptsType in acceptContentTypes) foreach (var acceptsType in acceptContentTypes)
{ {
// TODO: @bond move to Span when Span.Split lands
// https://github.com/dotnet/corefx/issues/26528
var contentType = acceptsType?.Split(';')[0]; var contentType = acceptsType?.Split(';')[0];
acceptsAnything = contentType.IndexOf("*/*", StringComparison.Ordinal) != -1; acceptsAnything = contentType.IndexOf("*/*", StringComparison.Ordinal) != -1;
@ -342,7 +320,7 @@ namespace Jellyfin.Server.SocketSharp
{ {
var mode = HandlerFactoryPath; var mode = HandlerFactoryPath;
var pos = request.RawUrl.IndexOf("?", StringComparison.Ordinal); var pos = request.RawUrl.IndexOf('?', StringComparison.Ordinal);
if (pos != -1) if (pos != -1)
{ {
var path = request.RawUrl.Substring(0, pos); var path = request.RawUrl.Substring(0, pos);
@ -524,10 +502,13 @@ namespace Jellyfin.Server.SocketSharp
public static string NormalizePathInfo(string pathInfo, string handlerPath) public static string NormalizePathInfo(string pathInfo, string handlerPath)
{ {
var trimmed = pathInfo.TrimStart('/'); if (handlerPath != null)
if (handlerPath != null && trimmed.StartsWith(handlerPath, StringComparison.OrdinalIgnoreCase))
{ {
return trimmed.Substring(handlerPath.Length); var trimmed = pathInfo.TrimStart('/');
if (trimmed.StartsWith(handlerPath, StringComparison.OrdinalIgnoreCase))
{
return trimmed.Substring(handlerPath.Length);
}
} }
return pathInfo; return pathInfo;