jetty-9 - HTTP client: implemented followRedirect functionality.

This commit is contained in:
Simone Bordet 2012-09-13 10:23:30 +02:00
parent 6be8ce9e26
commit b5a329ecaf
4 changed files with 22 additions and 6 deletions

View File

@ -438,7 +438,7 @@ public class HttpClient extends AggregateLifeCycle
}
// TODO: find a better method name
public Response.Listener lookup(Request request, Response response)
protected Response.Listener lookup(Request request, Response response)
{
for (ProtocolHandler handler : handlers)
{

View File

@ -45,19 +45,20 @@ public class HttpRequest implements Request
{
private static final AtomicLong ids = new AtomicLong();
private final HttpFields headers = new HttpFields();
private final Fields params = new Fields();
private final HttpClient client;
private final long id;
private String scheme;
private final String host;
private final int port;
private String scheme;
private String path;
private HttpMethod method;
private HttpVersion version;
private long idleTimeout;
private Listener listener;
private ContentProvider content;
private final HttpFields headers = new HttpFields();
private final Fields params = new Fields();
private boolean followRedirects = true;
public HttpRequest(HttpClient client, URI uri)
{
@ -266,9 +267,16 @@ public class HttpRequest implements Request
// return this;
// }
@Override
public boolean followRedirects()
{
return followRedirects;
}
@Override
public Request followRedirects(boolean follow)
{
this.followRedirects = follow;
return this;
}

View File

@ -45,7 +45,7 @@ public class RedirectProtocolHandler extends Response.Listener.Adapter implement
case 302:
case 303:
case 307:
return true;
return request.followRedirects() || client.isFollowRedirects();
}
return false;
}

View File

@ -181,7 +181,15 @@ public interface Request
*/
Request idleTimeout(long timeout);
// TODO
/**
* @return whether this request follows redirects
*/
boolean followRedirects();
/**
* @param follow whether this request follows redirects
* @return this request object
*/
Request followRedirects(boolean follow);
/**