Files
jellyfin-jellyfin-1/ServiceStack/HttpHandlerFactory.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2016-11-11 14:55:12 -05:00
using System;
using System.Collections.Generic;
using System.Linq;
2016-12-04 16:30:38 -05:00
using MediaBrowser.Model.Logging;
2016-11-11 14:55:12 -05:00
using MediaBrowser.Model.Services;
using ServiceStack.Host;
namespace ServiceStack
{
public class HttpHandlerFactory
{
// Entry point for HttpListener
2016-12-04 16:30:38 -05:00
public static RestHandler GetHandler(IHttpRequest httpReq, ILogger logger)
2016-11-11 14:55:12 -05:00
{
var pathInfo = httpReq.PathInfo;
var pathParts = pathInfo.TrimStart('/').Split('/');
2016-12-04 16:30:38 -05:00
if (pathParts.Length == 0)
{
logger.Error("Path parts empty for PathInfo: {0}, Url: {1}", pathInfo, httpReq.RawUrl);
return null;
}
2016-11-11 14:55:12 -05:00
string contentType;
var restPath = RestHandler.FindMatchingRestPath(httpReq.HttpMethod, pathInfo, logger, out contentType);
2016-11-11 14:55:12 -05:00
if (restPath != null)
{
return new RestHandler
{
RestPath = restPath,
RequestName = restPath.RequestType.GetOperationName(),
ResponseContentType = contentType
};
}
2016-11-11 14:55:12 -05:00
logger.Error("Could not find handler for {0}", pathInfo);
2016-11-11 14:55:12 -05:00
return null;
}
}
}