Class UserAgentWire

java.lang.Object
com.jcabi.http.wire.UserAgentWire
All Implemented Interfaces:
Wire

@Immutable public final class UserAgentWire extends Object implements Wire
Wire with default user agent.

This wire adds an extra HTTP header User-Agent to the request, if it's not yet provided, for example:

 String html = new JdkRequest("http://goggle.com")
   .through(UserAgentWire.class)
   .fetch()
   .body();

An actual HTTP request will be sent with User-Agent header with a value ReXSL-0.1/abcdef0 Java/1.6 (for example). It is recommended to use this wire decorator when you're working with third party RESTful services, to properly identify yourself and avoid troubles.

The class is immutable and thread-safe.

Since:
0.10
See Also:
  • Constructor Details

    • UserAgentWire

      public UserAgentWire(Wire wire)
      Public ctor.
      Parameters:
      wire - Original wire
  • Method Details

    • 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 interface Wire
      Parameters:
      req - Request
      home - URI to fetch
      method - HTTP method
      headers - Headers
      content - HTTP body
      connect - The connect timeout
      read - The read timeout
      Returns:
      Response obtained
      Throws:
      IOException - if fails