Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 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");
 }
Ejemplo n.º 3
0
 public void ItCanAddHeader()
 {
     var responseBuilder = new ResponseBuilder(Constants.RequestWithFile);
     var response = responseBuilder.Build();
     responseBuilder.AddHeader("Some", "Header");
     response.Headers["Some"].ShouldEqual("Header");
 }
Ejemplo n.º 4
0
 public Response Construct(IRequest request)
 {
     var responseBuilder = new ResponseBuilder(request);
     responseBuilder.SetStatusCode(404);
     responseBuilder.AppendToBody("404 - Not Found");
     return responseBuilder.Build();
 }
Ejemplo n.º 5
0
 public Response Construct(IRequest request)
 {
     var baseResponse = new HttpLibrary.Directors.FileResponse().Construct(request);
     var response = new ResponseBuilder(baseResponse).Build();
     TrimTrailingByte(response);
     return response;
 }
Ejemplo n.º 6
0
        public Response Construct(IRequest request)
        {
            var baseResponse = new HttpLibrary.Directors.GetResponse().Construct(request);
            var responseBuilder = new ResponseBuilder(baseResponse);

            AppendParamsToBody(request, responseBuilder);
            return responseBuilder.Build();
        }
Ejemplo n.º 7
0
 public void ItCanChangeTheStatusCode()
 {
     var responseBuilder = new ResponseBuilder(Constants.BasicRequest);
     var response = (responseBuilder.Build());
     response.StatusCode.ShouldEqual(404);
     responseBuilder.SetStatusCode(405);
     response.StatusCode.ShouldEqual(405);
 }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
 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();
 }
Ejemplo n.º 10
0
 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();
 }
Ejemplo n.º 11
0
 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();
 }
Ejemplo n.º 12
0
 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();
 }
Ejemplo n.º 13
0
 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();
 }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
 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");
 }
Ejemplo n.º 16
0
 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);
         }
     }
 }
Ejemplo n.º 17
0
 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");
 }
Ejemplo n.º 18
0
        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();
        }
Ejemplo n.º 19
0
 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();
 }
Ejemplo n.º 20
0
 public Response Construct(Response response, string resource)
 {
     var responseBuilder = new ResponseBuilder(response);
     responseBuilder.AddRedirect(resource);
     return responseBuilder.Build();
 }
Ejemplo n.º 21
0
 public Response Construct(IRequest request)
 {
     var responseBuilder = new ResponseBuilder(request);
     responseBuilder.SetStatusCode(405);
     return responseBuilder.Build();
 }