jellyfin/ServiceStack/HttpHandlerFactory.cs

32 lines
1 KiB
C#
Raw Normal View History

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