public APIGatewayProxyResponse Handle(APIGatewayProxyRequest request) { var response = _routeHandler.Handle(request); if (response.Headers == null) { response.Headers = new Dictionary <string, string>(); } if (_accessOrigins == null || _accessOrigins.Length == 0) { return(response); } var stringBuilder = new StringBuilder(); stringBuilder.Append(_accessOrigins[0]); for (var i = 1; i < _accessOrigins.Length; ++i) { stringBuilder.Append($",{_accessOrigins[i]}"); } response.Headers.Add("Access-Control-Allow-Origin", stringBuilder.ToString()); return(response); }
public async Task ProcessRequestAsync(Stream stream) { HttpResponse response = new HttpResponse(stream); HttpRequest request = null; bool isParseSuccess; try { request = await requestParser.ParseAsync(stream); isParseSuccess = true; } catch (HttpRequestParseException e) { response.StatusCode = 400; isParseSuccess = false; } if (!isParseSuccess) { await response.WriteAsync("Bad Request"); } HttpContext context = new HttpContext { Request = request, Response = response }; var func = routeHandler.Handle(request); if (func != null) { ActionResult actionResult = func(context); await actionResult.ExecuteAsync(context); } else { await(new Http404NotFoundResult()).ExecuteAsync(context); } }
private ConcurrentDictionary <string, RouteEntry> InitializeTable() { IEnumerable <string> ThrowNotSupported(Type request) => ThrowNotSupportedRouteHandler.Instance.Handle(request, null); var routeEntries = from component in _commandComponents let componentType = component.GetType() from routePath in _routeHandler.Handle(componentType, ThrowNotSupported) select new RouteEntry { RoutePath = routePath.ToLower(), RequestType = componentType, HandlerType = typeof(ICommandHandler <>).MakeGenericType(componentType) }; return(new ConcurrentDictionary <string, RouteEntry>( routeEntries.ToDictionary(routeEntry => routeEntry.RoutePath, routeEntry => routeEntry) )); }
public APIGatewayProxyResponse Handle(APIGatewayProxyRequest request) { try { return(_routeHandler.Handle(request)); } catch (Exception e) { Console.WriteLine(e); var statusCode = HttpStatusCode.InternalServerError; if (_exceptionToHttpStatusCode.ContainsKey(e.GetType())) { statusCode = _exceptionToHttpStatusCode[e.GetType()]; } return(new APIGatewayErrorResponse(e, statusCode)); } }
private ConcurrentDictionary <string, RouteEntry> InitializeTable() { IEnumerable <string> ThrowNotSupported(Type request) => ThrowNotSupportedRouteHandler.Instance.Handle(request, null); var routeEntries = from component in _queryComponents let componentType = component.GetType() let serviceType = componentType.GetInterfaces().Single( i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQuery <>) ) let resultType = serviceType.GenericTypeArguments[0] let handlerType = typeof(IQueryHandler <,>).MakeGenericType(componentType, resultType) from routePath in _routeHandler.Handle(componentType, ThrowNotSupported) select new RouteEntry { RoutePath = routePath.ToLower(), RequestType = componentType, HandlerType = handlerType }; return(new ConcurrentDictionary <string, RouteEntry>( routeEntries.ToDictionary(routeEntry => routeEntry.RoutePath, routeEntry => routeEntry) )); }