@Immutable public final class AutoRedirectingWire extends Object implements Wire
This wire will retry a request a certain number of times (default: 5)
after a short delay when a HTTP response with a status code of 300-399 is
received. On every next attempt a new URL will be used, according
to the value of Location
HTTP header of the response.
If the maximum number of retries are reached, the last response received is returned to the caller, regardless of its status code.
String html = new JdkRequest("http://goggle.com") .through(AutoRedirectingWire.class) .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN) .fetch() .body();
The class is immutable and thread-safe.
Constructor and Description |
---|
AutoRedirectingWire(Wire wire)
Public ctor.
|
AutoRedirectingWire(Wire wire,
int retries)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
Response |
send(Request req,
String home,
String method,
Collection<Map.Entry<String,String>> headers,
InputStream content)
Send request and return response.
|
public AutoRedirectingWire(Wire wire)
wire
- Original wirepublic AutoRedirectingWire(Wire wire, int retries)
wire
- Original wireretries
- Maximum number of retriespublic Response send(Request req, String home, String method, Collection<Map.Entry<String,String>> headers, InputStream content) throws IOException
Wire
send
in interface Wire
req
- Requesthome
- URI to fetchmethod
- HTTP methodheaders
- Headerscontent
- HTTP bodyIOException
- if failsCopyright © 2012–2014 jcabi.com. All rights reserved.