HttpHandlerFactory.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Model.Logging;
  5. using MediaBrowser.Model.Services;
  6. using ServiceStack.Host;
  7. namespace ServiceStack
  8. {
  9. public class HttpHandlerFactory
  10. {
  11. // Entry point for HttpListener
  12. public static RestHandler GetHandler(IHttpRequest httpReq, ILogger logger)
  13. {
  14. var pathInfo = httpReq.PathInfo;
  15. var pathParts = pathInfo.TrimStart('/').Split('/');
  16. if (pathParts.Length == 0)
  17. {
  18. logger.Error("Path parts empty for PathInfo: {0}, Url: {1}", pathInfo, httpReq.RawUrl);
  19. return null;
  20. }
  21. string contentType;
  22. var restPath = RestHandler.FindMatchingRestPath(httpReq.HttpMethod, pathInfo, out contentType);
  23. if (restPath != null)
  24. return new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.GetOperationName(), ResponseContentType = contentType };
  25. return null;
  26. }
  27. }
  28. }