Class RequestOptions

java.lang.Object
io.vertx.core.http.HttpConnectOptions
io.vertx.core.http.RequestOptions
Direct Known Subclasses:
WebSocketConnectOptions

public class RequestOptions extends HttpConnectOptions
Options describing how an HttpClient will connect to make a request.
Author:
Julien Viet
  • Field Details

    • DEFAULT_SERVER

      public static final SocketAddress DEFAULT_SERVER
      The default value for server method = null
    • DEFAULT_HTTP_METHOD

      public static final HttpMethod DEFAULT_HTTP_METHOD
      The default value for HTTP method = HttpMethod.GET
    • DEFAULT_HOST

      public static final String DEFAULT_HOST
      The default value for host name = null
    • DEFAULT_PORT

      public static final Integer DEFAULT_PORT
      The default value for port = null
    • DEFAULT_SSL

      public static final Boolean DEFAULT_SSL
      The default value for SSL = null
    • DEFAULT_URI

      public static final String DEFAULT_URI
      The default request URI = "/"
      See Also:
    • DEFAULT_FOLLOW_REDIRECTS

      public static final boolean DEFAULT_FOLLOW_REDIRECTS
      Follow redirection by default = false
      See Also:
    • DEFAULT_TIMEOUT

      public static final long DEFAULT_TIMEOUT
      The default request timeout = -1L (disabled)
      See Also:
    • DEFAULT_CONNECT_TIMEOUT

      public static final long DEFAULT_CONNECT_TIMEOUT
      The default connect timeout = -1L (disabled)
      See Also:
    • DEFAULT_IDLE_TIMEOUT

      public static final long DEFAULT_IDLE_TIMEOUT
      The default idle timeout = -1L (disabled)
      See Also:
  • Constructor Details

    • RequestOptions

      public RequestOptions()
      Default constructor
    • RequestOptions

      public RequestOptions(RequestOptions other)
      Copy constructor
      Parameters:
      other - the options to copy
    • RequestOptions

      public RequestOptions(JsonObject json)
      Create options from JSON
      Parameters:
      json - the JSON
  • Method Details

    • init

      protected void init()
      Overrides:
      init in class HttpConnectOptions
    • setProtocolVersion

      public RequestOptions setProtocolVersion(HttpVersion protocolVersion)
      Description copied from class: HttpConnectOptions
      Set the desired HTTP protocol version for this connection.
      Overrides:
      setProtocolVersion in class HttpConnectOptions
      Parameters:
      protocolVersion - the desired protocol version
      Returns:
      a reference to this, so the API can be used fluently
    • setProxyOptions

      public RequestOptions setProxyOptions(ProxyOptions proxyOptions)
      Description copied from class: HttpConnectOptions
      Override the HttpClientOptions.setProxyOptions(ProxyOptions) proxy options for connections.
      Overrides:
      setProxyOptions in class HttpConnectOptions
      Parameters:
      proxyOptions - proxy options override object
      Returns:
      a reference to this, so the API can be used fluently
    • setServer

      public RequestOptions setServer(Address server)
      Description copied from class: HttpConnectOptions
      Set the server address to be used by the client request.

      When the server address is null, the address will be resolved after the host property by the Vert.x resolver.

      Use this when you want to connect to a specific server address without name resolution.

      Overrides:
      setServer in class HttpConnectOptions
      Returns:
      a reference to this, so the API can be used fluently
    • getMethod

      public HttpMethod getMethod()
      Get the HTTP method to be used by the client request.
      Returns:
      the HTTP method
    • setMethod

      public RequestOptions setMethod(HttpMethod method)
      Set the HTTP method to be used by the client request.
      Returns:
      a reference to this, so the API can be used fluently
    • setHost

      public RequestOptions setHost(String host)
      Description copied from class: HttpConnectOptions
      Set the host name to be used by the client request.
      Overrides:
      setHost in class HttpConnectOptions
      Returns:
      a reference to this, so the API can be used fluently
    • setPort

      public RequestOptions setPort(Integer port)
      Description copied from class: HttpConnectOptions
      Set the port to be used by the client request.
      Overrides:
      setPort in class HttpConnectOptions
      Returns:
      a reference to this, so the API can be used fluently
    • setSsl

      public RequestOptions setSsl(Boolean ssl)
      Description copied from class: HttpConnectOptions
      Set whether SSL/TLS is enabled.
      Overrides:
      setSsl in class HttpConnectOptions
      Parameters:
      ssl - true if enabled
      Returns:
      a reference to this, so the API can be used fluently
    • setSslOptions

      public RequestOptions setSslOptions(ClientSSLOptions sslOptions)
      Description copied from class: HttpConnectOptions
      Set the SSL options to use.

      When none is provided, the client SSL options will be used instead.

      Overrides:
      setSslOptions in class HttpConnectOptions
      Parameters:
      sslOptions - the SSL options to use
      Returns:
      a reference to this, so the API can be used fluently
    • getURI

      public String getURI()
      Returns:
      the request relative URI
    • setURI

      public RequestOptions setURI(String uri)
      Set the request relative URI.
      Parameters:
      uri - the relative uri
      Returns:
      a reference to this, so the API can be used fluently
    • getFollowRedirects

      public Boolean getFollowRedirects()
      Returns:
      true when the client should follow redirection
    • setFollowRedirects

      public RequestOptions setFollowRedirects(Boolean followRedirects)
      Set whether to follow HTTP redirect
      Parameters:
      followRedirects - whether to follow redirect
      Returns:
      a reference to this, so the API can be used fluently
    • getTimeout

      public long getTimeout()
      See Also:
    • setTimeout

      public RequestOptions setTimeout(long timeout)
      Sets both connect and idle timeouts for the request
      • connect timeout: if the request is not obtained from the client within the timeout period, the Future<HttpClientRequest> obtained from the client is failed with a TimeoutException.
      • idle timeout: if the request does not return any data within the timeout period, the request/response is closed and the related futures are failed with a TimeoutException, e.g. Future<HttpClientResponse> or Future<Buffer> response body.
      The connect and idle timeouts can be set separately using setConnectTimeout(long) and setIdleTimeout(long)
    • setConnectTimeout

      public RequestOptions setConnectTimeout(long timeout)
      Description copied from class: HttpConnectOptions
      Sets the amount of time after which, if the request is not obtained from the client within the timeout period, the Future<HttpClientRequest> obtained from the client is failed with a TimeoutException. Note this is not related to the TCP HttpClientOptions.setConnectTimeout(int) option, when a request is made against a pooled HTTP client, the timeout applies to the duration to obtain a connection from the pool to serve the request, the timeout might fire because the server does not respond in time or the pool is too busy to serve a request.
      Overrides:
      setConnectTimeout in class HttpConnectOptions
      Parameters:
      timeout - the amount of time in milliseconds.
      Returns:
      a reference to this, so the API can be used fluently
    • getIdleTimeout

      public long getIdleTimeout()
      Returns:
      the amount of time after which, if the request does not return any data within the timeout period, the request/response is closed and the related futures are failed with a TimeoutException
    • setIdleTimeout

      public RequestOptions setIdleTimeout(long timeout)
      Sets the amount of time after which, if the request does not return any data within the timeout period, the request/response is closed and the related futures are failed with a TimeoutException, e.g. Future<HttpClientResponse> or Future<Buffer> response body.

      The timeout starts after a connection is obtained from the client, similar to calling HttpClientRequest.idleTimeout(long).

      Parameters:
      timeout - the amount of time in milliseconds.
      Returns:
      a reference to this, so the API can be used fluently
    • setAbsoluteURI

      public RequestOptions setAbsoluteURI(String absoluteURI)
      Parse an absolute URI to use, this will update the ssl, host, port and uri fields.
      Parameters:
      absoluteURI - the uri to use
      Returns:
      a reference to this, so the API can be used fluently
    • setAbsoluteURI

      public RequestOptions setAbsoluteURI(URL url)
      Like setAbsoluteURI(String) but using an URL parameter.
      Parameters:
      url - the uri to use
      Returns:
      a reference to this, so the API can be used fluently
    • addHeader

      public RequestOptions addHeader(String key, String value)
      Add a request header.
      Parameters:
      key - the header key
      value - the header value
      Returns:
      a reference to this, so the API can be used fluently
    • addHeader

      public RequestOptions addHeader(CharSequence key, CharSequence value)
      Add a request header.
      Parameters:
      key - the header key
      value - the header value
      Returns:
      a reference to this, so the API can be used fluently
    • addHeader

      public RequestOptions addHeader(CharSequence key, Iterable<CharSequence> values)
    • putHeader

      public RequestOptions putHeader(String key, String value)
      Set a request header.
      Parameters:
      key - the header key
      value - the header value
      Returns:
      a reference to this, so the API can be used fluently
    • putHeader

      public RequestOptions putHeader(CharSequence key, CharSequence value)
      Set a request header.
      Parameters:
      key - the header key
      value - the header value
      Returns:
      a reference to this, so the API can be used fluently
    • putHeader

      public RequestOptions putHeader(CharSequence key, Iterable<CharSequence> values)
    • removeHeader

      public RequestOptions removeHeader(String key)
      Add a request header.
      Parameters:
      key - the header key
      Returns:
      a reference to this, so the API can be used fluently
    • removeHeader

      public RequestOptions removeHeader(CharSequence key)
      Add a request header.
      Parameters:
      key - the header key
      Returns:
      a reference to this, so the API can be used fluently
    • setHeaders

      public RequestOptions setHeaders(MultiMap headers)
      Set request headers from a multi-map.
      Parameters:
      headers - the headers
      Returns:
      a reference to this, so the API can be used fluently
    • getHeaders

      public MultiMap getHeaders()
      Get the request headers
      Returns:
      the headers
    • getTraceOperation

      public String getTraceOperation()
      Returns:
      the trace operation override
    • setTraceOperation

      public RequestOptions setTraceOperation(String op)
      Override the operation the tracer use for this request. When no operation is set, the HTTP method is used instead.
      Parameters:
      op - the override
      Returns:
      a reference to this, so the API can be used fluently
    • getRoutingKey

      public String getRoutingKey()
      Return the routing key, the routing key can be used by a Vert.x client side sticky load balancer to pin the request to a remote HTTP server.
      Returns:
      the routing key
    • setRoutingKey

      public RequestOptions setRoutingKey(String key)
      Set the routing key, the routing key can be used by a Vert.x client side sticky load balancer to pin the request to a remote HTTP server.
      Parameters:
      key - the routing key
      Returns:
      a reference to this, so the API can be used fluently
    • toJson

      public JsonObject toJson()
      Overrides:
      toJson in class HttpConnectOptions