public static IHttpHandler GetHandlerForPathInfo(string httpMethod, string pathInfo, string filePath) { var pathParts = pathInfo.TrimStart('/').Split('/'); if (pathParts.Length == 0) { return(new NotFoundHttpHandler()); } var handler = GetHandlerForPathParts(pathParts); if (handler != null) { return(handler); } var existingFile = pathParts[0].ToLower(); if (WebHostRootFileNames.Contains(existingFile)) { return(ShouldAllow(filePath) ? StaticFileHandler : ForbiddenHttpHandler); } var restPath = RestHandler.FindMatchingRestPath(httpMethod, pathInfo); return(restPath != null ? new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.Name } : null); }
public static IHttpHandler GetHandlerForPathInfo(string httpMethod, string pathInfo) { var pathParts = pathInfo.TrimStart('/').Split('/'); if (pathParts.Length == 0) { return(new NotFoundHttpHandler()); } var handler = GetHandlerForPathParts(pathParts); if (handler != null) { return(handler); } var existingFile = pathParts[0].ToLower(); if (WebHostRootFileNames.Contains(existingFile)) { //Avoid recursive redirections return(!UsingIntegratedPipeline ? DefaultHttpHandler : new StaticFileHandler()); } var restPath = RestHandler.FindMatchingRestPath(httpMethod, pathInfo); return(restPath != null ? new RestHandler { RestPath = restPath, RequestName = pathInfo } : null); }
public static IHttpHandler GetHandlerForPathInfo(string httpMethod, string pathInfo, string requestPath, string filePath) { var pathParts = pathInfo.TrimStart('/').Split('/'); if (pathParts.Length == 0) { return(NotFoundHttpHandler); } var existingFile = pathParts[0].ToLower(); if (WebHostRootFileNames.Contains(existingFile)) { var fileExt = Path.GetExtension(filePath); var isFileRequest = !string.IsNullOrEmpty(fileExt); if (!isFileRequest && !AutoRedirectsDirs) { //If pathInfo is for Directory try again with redirect including '/' suffix if (!pathInfo.EndsWith("/")) { var appFilePath = filePath.Substring(0, filePath.Length - requestPath.Length); var redirect = Support.StaticFileHandler.DirectoryExists(filePath, appFilePath); if (redirect) { return(new RedirectHttpHandler { RelativeUrl = pathInfo + "/", }); } } } //e.g. CatchAllHandler to Process Markdown files var catchAllHandler = GetCatchAllHandlerIfAny(httpMethod, pathInfo, filePath); if (catchAllHandler != null) { return(catchAllHandler); } if (!isFileRequest) { return(NotFoundHttpHandler); } return(ShouldAllow(requestPath) ? StaticFileHandler : ForbiddenHttpHandler); } var restPath = RestHandler.FindMatchingRestPath(httpMethod, pathInfo); if (restPath != null) { return new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.Name } } ; return(GetCatchAllHandlerIfAny(httpMethod, pathInfo, filePath)); }
public void Can_parse_Ips() { var handler = new RestHandler(); var result = handler.GetEndpointAttributes(CreateRequest("204.2.145.235")); Assert.That(result.Has(EndpointAttributes.External)); Assert.That(result.Has(EndpointAttributes.HttpGet)); Assert.That(result.Has(EndpointAttributes.InSecure)); }
public static IHttpHandler GetHandlerForPathInfo(string httpMethod, string pathInfo, string requestPath, string filePath) { var pathParts = pathInfo.TrimStart('/').Split('/'); if (pathParts.Length == 0) { return(NotFoundHttpHandler); } var handler = GetHandlerForPathParts(pathParts); if (handler != null) { return(handler); } var existingFile = pathParts[0].ToLower(); if (WebHostRootFileNames.Contains(existingFile)) { //e.g. CatchAllHandler to Process Markdown files var catchAllHandler = GetCatchAllHandlerIfAny(httpMethod, pathInfo, filePath); if (catchAllHandler != null) { return(catchAllHandler); } var fileExt = Path.GetExtension(filePath); if (string.IsNullOrEmpty(fileExt)) { return(NotFoundHttpHandler); } return(ShouldAllow(requestPath) ? StaticFileHandler : ForbiddenHttpHandler); } var restPath = RestHandler.FindMatchingRestPath(httpMethod, pathInfo); if (restPath != null) { return new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.Name } } ; return(GetCatchAllHandlerIfAny(httpMethod, pathInfo, filePath)); }
public void Can_deserialize_TestRequest_QueryStringSerializer_output() { // Setup var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly); var restPath = new RestPath(typeof(TestRequest), "/service", "GET"); var restHandler = new RestHandler { RestPath = restPath }; var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}"; NameValueCollection queryString = HttpUtility.ParseQueryString(requestString); var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection()); var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service"); Assert.That(request2.ListOfA.Count, Is.EqualTo(1)); Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2)); }