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;
|
2017-02-12 17:53:14 -05:00
|
|
|
var restPath = RestHandler.FindMatchingRestPath(httpReq.HttpMethod, pathInfo, logger, out contentType);
|
|
|
|
|
|
2016-11-11 14:55:12 -05:00
|
|
|
if (restPath != null)
|
2017-02-12 17:53:14 -05:00
|
|
|
{
|
|
|
|
|
return new RestHandler
|
|
|
|
|
{
|
|
|
|
|
RestPath = restPath,
|
|
|
|
|
RequestName = restPath.RequestType.GetOperationName(),
|
|
|
|
|
ResponseContentType = contentType
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-11-11 14:55:12 -05:00
|
|
|
|
2017-02-12 17:53:14 -05:00
|
|
|
logger.Error("Could not find handler for {0}", pathInfo);
|
2016-11-11 14:55:12 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|