Class BasicHttpRequest

java.lang.Object
org.apache.hc.core5.http.message.HeaderGroup
org.apache.hc.core5.http.message.BasicHttpRequest
All Implemented Interfaces:
Serializable, HttpMessage, HttpRequest, MessageHeaders
Direct Known Subclasses:
BasicClassicHttpRequest

public class BasicHttpRequest extends HeaderGroup implements HttpRequest
Basic implementation of HttpRequest.
Since:
4.0
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • method

      private final String method
    • path

      private String path
    • scheme

      private String scheme
    • authority

      private URIAuthority authority
    • version

      private ProtocolVersion version
    • requestUri

      private URI requestUri
    • absoluteRequestUri

      private boolean absoluteRequestUri
  • Constructor Details

    • BasicHttpRequest

      public BasicHttpRequest(String method, String scheme, URIAuthority authority, String path)
      Creates request message with the given method, host and request path.
      Parameters:
      method - request method.
      scheme - request scheme.
      authority - request authority.
      path - request path.
      Since:
      5.1
    • BasicHttpRequest

      public BasicHttpRequest(String method, String path)
      Creates request message with the given method and request path.
      Parameters:
      method - request method.
      path - request path.
    • BasicHttpRequest

      public BasicHttpRequest(String method, HttpHost host, String path)
      Creates request message with the given method, host and request path.
      Parameters:
      method - request method.
      host - request host.
      path - request path.
      Since:
      5.0
    • BasicHttpRequest

      public BasicHttpRequest(String method, URI requestUri)
      Creates request message with the given method, request URI.
      Parameters:
      method - request method.
      requestUri - request URI.
      Since:
      5.0
    • BasicHttpRequest

      public BasicHttpRequest(Method method, String path)
      Creates request message with the given method and request path.
      Parameters:
      method - request method.
      path - request path.
      Since:
      5.0
    • BasicHttpRequest

      public BasicHttpRequest(Method method, HttpHost host, String path)
      Creates request message with the given method, host and request path.
      Parameters:
      method - request method.
      host - request host.
      path - request path.
      Since:
      5.0
    • BasicHttpRequest

      public BasicHttpRequest(Method method, URI requestUri)
      Creates request message with the given method, request URI.
      Parameters:
      method - request method.
      requestUri - request URI.
      Since:
      5.0
  • Method Details

    • addHeader

      public void addHeader(String name, Object value)
      Description copied from interface: HttpMessage
      Adds a header to this message. The header will be appended to the end of the list.
      Specified by:
      addHeader in interface HttpMessage
      Parameters:
      name - the name of the header.
      value - the value of the header, taken as the value's Object.toString().
    • setHeader

      public void setHeader(String name, Object value)
      Description copied from interface: HttpMessage
      Overwrites the first header with the same name. The new header will be appended to the end of the list, if no header with the given name can be found.
      Specified by:
      setHeader in interface HttpMessage
      Parameters:
      name - the name of the header.
      value - the value of the header, taken as the value's Object.toString().
    • setVersion

      public void setVersion(ProtocolVersion version)
      Description copied from interface: HttpMessage
      Sets protocol version.

      For incoming messages it represents protocol version this message was transmitted with. For outgoing messages it represents a hint what protocol version should be used to transmit the message.

      Specified by:
      setVersion in interface HttpMessage
    • getVersion

      public ProtocolVersion getVersion()
      Description copied from interface: HttpMessage
      Returns protocol version or null when not available.

      For incoming messages it represents protocol version this message was transmitted with. For outgoing messages it represents a hint what protocol version should be used to transmit the message.

      Specified by:
      getVersion in interface HttpMessage
    • getMethod

      public String getMethod()
      Description copied from interface: HttpRequest
      Returns method of this request message.
      Specified by:
      getMethod in interface HttpRequest
      Returns:
      the request method.
    • getPath

      public String getPath()
      Description copied from interface: HttpRequest
      Returns URI path of this request message or null if not set.
      Specified by:
      getPath in interface HttpRequest
      Returns:
      the request URI or null.
    • setPath

      public void setPath(String path)
      Description copied from interface: HttpRequest
      Sets URI path of this request message.
      Specified by:
      setPath in interface HttpRequest
    • getScheme

      public String getScheme()
      Description copied from interface: HttpRequest
      Returns scheme of this request message.
      Specified by:
      getScheme in interface HttpRequest
      Returns:
      the scheme or null.
    • setScheme

      public void setScheme(String scheme)
      Description copied from interface: HttpRequest
      Sets scheme of this request message.
      Specified by:
      setScheme in interface HttpRequest
    • getAuthority

      public URIAuthority getAuthority()
      Description copied from interface: HttpRequest
      Returns authority of this request message.
      Specified by:
      getAuthority in interface HttpRequest
      Returns:
      the authority or null.
    • setAuthority

      public void setAuthority(URIAuthority authority)
      Description copied from interface: HttpRequest
      Sets authority of this request message.
      Specified by:
      setAuthority in interface HttpRequest
    • setAbsoluteRequestUri

      public void setAbsoluteRequestUri(boolean absoluteRequestUri)
      Sets a flag that the getRequestUri() method should return the request URI in an absolute form.

      This flag can used when the request is going to be transmitted via an HTTP/1.1 proxy.

      Since:
      5.1
    • getRequestUri

      public String getRequestUri()
      Description copied from interface: HttpRequest
      Returns request URI of this request message. It may be an absolute or relative URI. Applicable to HTTP/1.1 version or earlier.
      Specified by:
      getRequestUri in interface HttpRequest
      Returns:
      the request URI.
    • setUri

      public void setUri(URI requestUri)
      Description copied from interface: HttpRequest
      Sets the full request URI of this request message.
      Specified by:
      setUri in interface HttpRequest
      Parameters:
      requestUri - the request URI.
    • assembleRequestUri

      private void assembleRequestUri(StringBuilder buf)
    • getUri

      public URI getUri() throws URISyntaxException
      Description copied from interface: HttpRequest
      Returns full request URI of this request message.
      Specified by:
      getUri in interface HttpRequest
      Returns:
      the request URI.
      Throws:
      URISyntaxException
    • toString

      public String toString()
      Overrides:
      toString in class HeaderGroup