public Response Construct(IRequest request) { var responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(200); responseBuilder.AddHeader(Headers.Allow, "GET,HEAD,POST,OPTIONS,PUT"); return responseBuilder.Build(); }
public void ItCanChainCommands() { var responseBuilder = new ResponseBuilder(Constants.BasicRequest); var response = responseBuilder.SetStatusCode(404).AppendToBody("HELLO").Build(); response.StatusCode.ShouldEqual(404); response.ToString().ShouldContain("HELLO"); }
public void ItCanAddHeader() { var responseBuilder = new ResponseBuilder(Constants.RequestWithFile); var response = responseBuilder.Build(); responseBuilder.AddHeader("Some", "Header"); response.Headers["Some"].ShouldEqual("Header"); }
public Response Construct(IRequest request) { var responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(404); responseBuilder.AppendToBody("404 - Not Found"); return responseBuilder.Build(); }
public Response Construct(IRequest request) { var baseResponse = new HttpLibrary.Directors.FileResponse().Construct(request); var response = new ResponseBuilder(baseResponse).Build(); TrimTrailingByte(response); return response; }
public Response Construct(IRequest request) { var baseResponse = new HttpLibrary.Directors.GetResponse().Construct(request); var responseBuilder = new ResponseBuilder(baseResponse); AppendParamsToBody(request, responseBuilder); return responseBuilder.Build(); }
public void ItCanChangeTheStatusCode() { var responseBuilder = new ResponseBuilder(Constants.BasicRequest); var response = (responseBuilder.Build()); response.StatusCode.ShouldEqual(404); responseBuilder.SetStatusCode(405); response.StatusCode.ShouldEqual(405); }
public void ItCanAddARedirect() { var responseBuilder = new ResponseBuilder(Constants.RequestWithFile); responseBuilder.AddRedirect("/"); var response = responseBuilder.Build(); response.StatusCode.ShouldEqual(302); response.Headers.Keys.ShouldContain(Headers.Location); }
public Response Construct(IRequest request) { var responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(401); responseBuilder.AddHeader(Headers.Authenticate, "Basic"); responseBuilder.AppendToBody("Authentication required"); return responseBuilder.Build(); }
public Response Construct(IRequest request) { _responseBuilder = new ResponseBuilder(request); _responseBuilder.SetStatusCode(200); _responseBuilder.AddHeader(Headers.ContentType, MimeTypes.GetType(".html")); AddQuote(request); AddNewQuoteLink(); return _responseBuilder.Build(); }
public Response Construct(IRequest request) { var viewDirectory = Environment.GetEnvironmentVariable("ViewDirectory"); var responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(200); responseBuilder.AddHeader(Headers.ContentType, MimeTypes.GetType(".css")); responseBuilder.AppendToBody(File.ReadAllBytes(viewDirectory + request.Resource)); return responseBuilder.Build(); }
public Response Construct(IRequest request, string allowedMethods) { Construct(request); var responseBuilder = new ResponseBuilder(_response); var methods = Methods.Get + "," + Methods.Head; if (allowedMethods != string.Empty) methods += "," + allowedMethods; responseBuilder.AddHeader(Headers.Allow, methods); return responseBuilder.Build(); }
public Response Construct(IRequest request) { var directory = Environment.GetEnvironmentVariable("directory"); var responseBuilder = new ResponseBuilder(request); if (File.Exists(directory + request.Resource)) TryPatchFile(request, directory, responseBuilder); else SetFileNotFound(responseBuilder); return responseBuilder.Build(); }
public Response Construct(IRequest request) { var responseBuilder = new ResponseBuilder(request); if (IsAForm(request)) WriteForm(request, responseBuilder); else WriteRequestBody(request); responseBuilder.SetStatusCode(200); return responseBuilder.Build(); }
private void WriteForm(IRequest request, ResponseBuilder responseBuilder) { var fileName = GetParamValue(request, "fileName"); var data = GetParamValue(request, "data"); var directory = Environment.GetEnvironmentVariable("directory"); lock (thisLock) { File.WriteAllText(directory + "/" + fileName, HtmlTools.GenerateForm(fileName, data)); } responseBuilder.AddHeader(Headers.ContentType, "text/html"); }
private static void AppendParamsToBody(IRequest request, ResponseBuilder responseBuilder) { if (request.HasParams()) { foreach (var param in request.Params) { var paramString = param.Key + " = " + param.Value + "\n"; responseBuilder.AppendToBody(paramString); } } }
public void ItCanAppendToTheBody() { var responseBuilder = new ResponseBuilder(Constants.RequestWithFile); var stringContent = "ADD-ME"; var byteContent = Encoding.ASCII.GetBytes("ME-TOO"); responseBuilder.AppendToBody(stringContent); responseBuilder.AppendToBody(byteContent); var response = responseBuilder.Build(); var responseString = Encoding.ASCII.GetString(response.GetBytes()); responseString.ShouldContain("ADD-ME"); responseString.ShouldContain("ME-TOO"); }
public Response Construct(IRequest request) { var directory = Environment.GetEnvironmentVariable("directory"); var fileName = request.Params.ContainsKey("fileName") ? request.Params["fileName"] : request.Resource; if (!File.Exists(directory+fileName)) return (new FourOhFourResponse()).Construct(request); File.Delete(directory+fileName); var responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(200); responseBuilder.AppendToBody(request.Resource + " successfully deleted."); return responseBuilder.Build(); }
public Response Construct(IRequest request) { var directory = Environment.GetEnvironmentVariable("directory"); var responseBuilder = new ResponseBuilder(request); var path = HexCode.ConvertToString(directory + request.Resource); responseBuilder.SetStatusCode(200); var file = File.ReadAllBytes(path); responseBuilder.AppendToBody(file); responseBuilder.AddHeader(Headers.ContentType, ResponseUtils.GetFileType(path)); if (request.Headers.ContainsKey(Headers.Range)) responseBuilder.AddHeader(Headers.ContentRange, request.Headers[Headers.Range]); return responseBuilder.Build(); }
public Response Construct(Response response, string resource) { var responseBuilder = new ResponseBuilder(response); responseBuilder.AddRedirect(resource); return responseBuilder.Build(); }
public Response Construct(IRequest request) { var responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(405); return responseBuilder.Build(); }