jetty-9 - HTTP client: implemented followRedirect functionality.
This commit is contained in:
parent
6be8ce9e26
commit
b5a329ecaf
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue