lantunes / fixd

An HTTP Server Fixture for Testing HTTP Clients and mocking web services, and a Java Micro Web Framework
http://bigtesting.org/fixd
Apache License 2.0
41 stars 6 forks source link

Provide a convenient mechanism for sending redirects #10

Closed lantunes closed 10 years ago

lantunes commented 10 years ago

Currently, the user must manually set header information if they want to send a redirect response. It would be more convenient if there were methods that already existed for sending a redirect, so that less work would be required of the user.

The server itself should provide a mechanism:

server.handle(Method.GET, "/")
      .withRedirect("http://localhost:8080/new-location");
server.handle(Method.GET, "/")
      .withRedirect("http://localhost:8080/new-location", 301);

Also, the response object should allow the user to do the same, in the case of custom request handling:

server.handle(Method.GET, "/")
      .with(new HttpRequestHandler() {
          public void handle(HttpRequest request, HttpResponse response) {                    
             response.redirect("http://localhost:8080/new-location");
          }
      });
server.handle(Method.GET, "/")
      .with(new HttpRequestHandler() {
          public void handle(HttpRequest request, HttpResponse response) {                    
             response.redirect("http://localhost:8080/new-location", 301);
          }
      });