public HttpResponse GetResponse() { var response = new HttpResponse(this.Request.ProtocolVersion, this.GetStatusCode(), this.GetContent(), HighQualityCodeExamPointsProvider.GetContentType()); foreach (var responseHeader in this.ResponseHeaders) { response.AddHeader(responseHeader.Key, responseHeader.Value); } return response; }
public HttpResponse Handle(HttpRq request) { String filePath = Environment.CurrentDirectory + "/" + request.Uri; if (!this.FileExists("C:\\", filePath, 3)) { return new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotFound, "File not found"); } String fileContents = File.ReadAllText(filePath); var response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.OK, fileContents); return response; }
private HttpResponse Process(HttpRq request) { if (request.Method.ToLower() == "options") { var routes = Assembly.GetEntryAssembly().GetTypes() .Where(x => x.Name.EndsWith("Controller") && typeof(Controller).IsAssignableFrom(x)) .Select(x => new { x.Name, Methods = x.GetMethods().Where(m => m.ReturnType == typeof(IActionResult)) }) .SelectMany(x => x.Methods.Select(m => string.Format("/{0}/{1}/{{parameter}}", x.Name.Replace("Controller", string.Empty), m.Name))) .ToList(); return new HttpResponse(request.ProtocolVersion, HttpStatusCode.OK, string.Join(Environment.NewLine, routes)); } else if (new StaticFileHandler().CanHandle(request)) { return new StaticFileHandler().Handle(request); } else if (request.ProtocolVersion.Major <= 3) { HttpResponse response; try { var controller = this.CreateController(request); var actionInvoker = new NewActionInvoker(); var actionResult = actionInvoker.InvokeAction(controller, request.Action); response = actionResult.GetResponse(); } catch (HttpNotFound exception) { response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotFound, exception.Message); } catch (Exception exception) { response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.InternalServerError, exception.Message); } return response; } else { return new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotImplemented, NotHandledRequest); } }