2016-11-11 19:55:12 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2016-12-04 21:30:38 +00:00
|
|
|
using MediaBrowser.Model.Logging;
|
2016-11-11 19:55:12 +00:00
|
|
|
using MediaBrowser.Model.Services;
|
|
|
|
using ServiceStack.Host;
|
|
|
|
|
|
|
|
namespace ServiceStack
|
|
|
|
{
|
|
|
|
public class HttpHandlerFactory
|
|
|
|
{
|
|
|
|
// Entry point for HttpListener
|
2016-12-04 21:30:38 +00:00
|
|
|
public static RestHandler GetHandler(IHttpRequest httpReq, ILogger logger)
|
2016-11-11 19:55:12 +00:00
|
|
|
{
|
|
|
|
var pathInfo = httpReq.PathInfo;
|
|
|
|
|
|
|
|
var pathParts = pathInfo.TrimStart('/').Split('/');
|
2016-12-04 21:30:38 +00:00
|
|
|
if (pathParts.Length == 0)
|
|
|
|
{
|
|
|
|
logger.Error("Path parts empty for PathInfo: {0}, Url: {1}", pathInfo, httpReq.RawUrl);
|
|
|
|
return null;
|
|
|
|
}
|
2016-11-11 19:55:12 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|