예제 #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();
 }
예제 #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");
 }
예제 #3
0
 public void ItCanAddHeader()
 {
     var responseBuilder = new ResponseBuilder(Constants.RequestWithFile);
     var response = responseBuilder.Build();
     responseBuilder.AddHeader("Some", "Header");
     response.Headers["Some"].ShouldEqual("Header");
 }
예제 #4
0
 public Response Construct(IRequest request)
 {
     var responseBuilder = new ResponseBuilder(request);
     responseBuilder.SetStatusCode(404);
     responseBuilder.AppendToBody("404 - Not Found");
     return responseBuilder.Build();
 }
예제 #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;
 }
예제 #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();
        }
예제 #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);
 }
예제 #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);
 }
예제 #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();
 }
예제 #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();
 }
예제 #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();
 }
예제 #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();
 }
예제 #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();
 }
예제 #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();
        }
예제 #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");
 }
예제 #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);
         }
     }
 }
예제 #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");
 }
예제 #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();
        }
예제 #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();
 }
예제 #20
0
 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();
 }