Package com.jcabi.http.wire
Class AutoRedirectingWire
- java.lang.Object
-
- com.jcabi.http.wire.AutoRedirectingWire
-
- All Implemented Interfaces:
Wire
@Immutable public final class AutoRedirectingWire extends Object implements Wire
Auto Redirecting 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.
- Since:
- 1.6
-
-
Constructor Summary
Constructors Constructor Description AutoRedirectingWire(Wire wire)
Public ctor.AutoRedirectingWire(Wire wire, int retries)
Public ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Response
send(Request req, String home, String method, Collection<Map.Entry<String,String>> headers, InputStream content, int connect, int read)
Send request and return response.
-
-
-
Method Detail
-
send
public Response send(Request req, String home, String method, Collection<Map.Entry<String,String>> headers, InputStream content, int connect, int read) throws IOException
Description copied from interface:Wire
Send request and return response.- Specified by:
send
in interfaceWire
- Parameters:
req
- Requesthome
- URI to fetchmethod
- HTTP methodheaders
- Headerscontent
- HTTP bodyconnect
- The connect timeoutread
- The read timeout- Returns:
- Response obtained
- Throws:
IOException
- if fails
-
-