HttpHandlerFactory.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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, logger, out contentType);
  23. if (restPath != null)
  24. {
  25. return new RestHandler
  26. {
  27. RestPath = restPath,
  28. RequestName = restPath.RequestType.GetOperationName(),
  29. ResponseContentType = contentType
  30. };
  31. }
  32. logger.Error("Could not find handler for {0}", pathInfo);
  33. return null;
  34. }
  35. }
  36. }