Interface HttpRequestBuilder


public interface HttpRequestBuilder
Builds an HTTP request, allows for adding listeners for response events, and for launching such a request.
Author:
Tim Boudreau
  • Method Details

    • addHeader

      <T> HttpRequestBuilder addHeader(HeaderValueType<T> type, T value)
      Add a request header. The Headers class implements a lot of common header types.
      Type Parameters:
      T - The header type
      Parameters:
      type - The header type
      value - The value
      Returns:
      this
    • addPathElement

      HttpRequestBuilder addPathElement(String element)
      Append a path element to the URL
      Parameters:
      element - a path element
      Returns:
      this
    • addQueryPair

      HttpRequestBuilder addQueryPair(String key, String value)
      Add a query key/value pair to the URL
      Parameters:
      key - A key
      value - A value
      Returns:
      this
    • addQueryPairs

      default HttpRequestBuilder addQueryPairs(Map<String,Object> pairs, Function<Object,String> toString)
    • addQueryPairs

      default HttpRequestBuilder addQueryPairs(Map<String,String> pairs)
    • setAnchor

      HttpRequestBuilder setAnchor(String anchor)
      Set the anchor portion of the URL
      Parameters:
      anchor - The anchor
      Returns:
      this
    • setHost

      HttpRequestBuilder setHost(String host)
      Set the host portion of the URL
      Parameters:
      host -
      Returns:
    • setPath

      HttpRequestBuilder setPath(String path)
      Set the complete path of the URL (clobbering any earlier calls to add path elements)
      Parameters:
      path - the path
      Returns:
      this
    • setPort

      HttpRequestBuilder setPort(int port)
      Set the port
      Parameters:
      port - The port
      Returns:
      this
    • setProtocol

      HttpRequestBuilder setProtocol(Protocol protocol)
      Set the protocol. See the Protocols enum for common values.
      Parameters:
      protocol -
      Returns:
    • setURL

      HttpRequestBuilder setURL(URL url)
      Set the whole URL, clobbering any earlier settings
      Parameters:
      url -
      Returns:
    • setURL

      Set the whole URL, clobbering any earlier settings
      Parameters:
      url -
      Returns:
    • setUserName

      HttpRequestBuilder setUserName(String userName)
      Set the user name that will be put in the URL - note this is distinct from basic authentication - it results in urls such as http://user:password@host/path
      Parameters:
      userName -
      Returns:
    • setPassword

      HttpRequestBuilder setPassword(String password)
      Set the password that will be put in the URL - note this is distinct from basic authentication - it results in urls such as http://user:password@host/path
      Parameters:
      userName -
      Returns:
      this
    • basicAuthentication

      HttpRequestBuilder basicAuthentication(String username, String password)
      Set basic auth credentials
      Parameters:
      username - The username
      password - The password
      Returns:
      this
    • execute

      ResponseFuture execute(ResponseHandler<?> response)
      Launch the request
      Parameters:
      response -
      Returns:
    • execute

      ResponseFuture execute()
      Launch the request
      Returns:
    • setBody

      HttpRequestBuilder setBody(Object o, com.mastfrog.mime.MimeType contentType) throws IOException
      Set the request body. May be a string, byte array, ByteBuf, InputStream, Image or an Object which can be converted to JSON by a vanilla ObjectMapper.

      For custom serialization, convert to a byte stream first.

      Parameters:
      o - The body
      Returns:
      Throws:
      IOException
    • on

      <T> HttpRequestBuilder on(Class<? extends State<T>> event, Receiver<T> r)
      Add an event handler for a particular event
      Type Parameters:
      T -
      Parameters:
      event - The event type
      r - The handler. If the handler is the wrong type for the object of this event, it will be called with null.
      Returns:
      this
    • on

      <T> HttpRequestBuilder on(StateType event, Receiver<T> r)
      Add an event handler for a particular event, using enum constants. Use this to pick up events like connected, closed, etc. Note that it is possible to pass a Receiver for the wrong type here. In that case a warning will be logged when it is called, and you will be passed null instead. Simple events like connecting and close take Void, and will always be passed null.
      Type Parameters:
      T - The type of object this event produces
      Parameters:
      event - The type of event
      r - A callback which will be called with the event contents zero or more times
      Returns:
      this
    • onEvent

      Add an event handler which will be called for every event
      Parameters:
      r - An event handler
      Returns:
      this
    • toURL

      URL toURL()
      Get the URL as it currently stands for this request
      Returns:
      A url
    • noHostHeader

      HttpRequestBuilder noHostHeader()
      Don't sent the host header from the URL
      Returns:
      this
    • noConnectionHeader

      HttpRequestBuilder noConnectionHeader()
      Don't send the connection header
      Returns:
      this
    • noDateHeader

      HttpRequestBuilder noDateHeader()
      Don't create a Date: header
      Returns:
      this
    • setCookieStore

      HttpRequestBuilder setCookieStore(CookieStore store)
      Set a cookie store which will be updated from Set-Cookie headers in the response, and which will decorate the request with any Cookies it has that match the request URL.
      Parameters:
      store - The cookie store
      Returns:
      this
    • setTimeout

      HttpRequestBuilder setTimeout(Duration timeout)
    • dontAggregateResponse

      HttpRequestBuilder dontAggregateResponse()
      If called, the request builder will not aggregate http chunks, and the full http response will not be sent to listeners. Use this for large uploads where you intend to store the incoming chunks to disk or some other not-in-ram storage as they arrive.
      Returns:
      this