HttpHandlerFactory.cs 846 B

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