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 responseBuilder = new ResponseBuilder(request); responseBuilder.SetStatusCode(404); responseBuilder.AppendToBody("404 - Not Found"); return responseBuilder.Build(); }
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) { 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(); }
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 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(); }