org.apache.hc.core5.http.message

## 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:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicHttpRequest(Method method, HttpHost host, String path)` Creates request message with the given method, host and request path.
    `BasicHttpRequest(Method method, String path)` Creates request message with the given method and request path.
    `BasicHttpRequest(Method method, URI requestUri)` Creates request message with the given method, request URI.
    `BasicHttpRequest(String method, HttpHost host, String path)` Creates request message with the given method, host and request path.
    `BasicHttpRequest(String method, String path)` Creates request message with the given method and request path.
    `BasicHttpRequest(String method, String scheme, URIAuthority authority, String path)` Creates request message with the given method, host and request path.
    `BasicHttpRequest(String method, URI requestUri)` Creates request message with the given method, request URI.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addHeader(String name, Object value)` Adds a header to this message.
    `URIAuthority` | `getAuthority()` Returns authority of this request message.
    `String` | `getMethod()` Returns method of this request message.
    `String` | `getPath()` Returns URI path of this request message or `null` if not set.
    `String` | `getRequestUri()` Returns request URI of this request message.
    `String` | `getScheme()` Returns scheme of this request message.
    `URI` | `getUri()` Returns full request URI of this request message.
    `ProtocolVersion` | `getVersion()` Returns protocol version or `null` when not available.
    `void` | `setAbsoluteRequestUri(boolean absoluteRequestUri)` Sets whether `getRequestUri()` should return the request URI in an absolute form.
    `void` | `setAuthority(URIAuthority authority)` Sets authority of this request message.
    `void` | `setHeader(String name, Object value)` Overwrites the first header with the same name.
    `void` | `setPath(String path)` Sets URI path of this request message.
    `void` | `setScheme(String scheme)` Sets scheme of this request message.
    `void` | `setUri(URI requestUri)` Sets the full request URI of this request message.
    `void` | `setVersion(ProtocolVersion version)` Sets protocol version.
    `String` | `toString()`

    - ### Methods inherited from class org.apache.hc.core5.http.message.HeaderGroup

      `addHeader, clear, containsHeader, countHeaders, getCondensedHeader, getFirstHeader, getHeader, getHeaders, getHeaders, getLastHeader, headerIterator, headerIterator, removeHeader, removeHeaders, removeHeaders, setHeader, setHeaders`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.hc.core5.http.HttpMessage

      `addHeader, removeHeader, removeHeaders, setHeader, setHeaders`

    - ### Methods inherited from interface org.apache.hc.core5.http.MessageHeaders

      `containsHeader, countHeaders, getFirstHeader, getHeader, getHeaders, getHeaders, getLastHeader, headerIterator, headerIterator`

- - ### Constructor Detail

    - #### 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 Detail

    - #### 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`
      Parameters:
        `version` - The protocol version.

    - #### 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`
      Returns:
        The protocol version.

    - #### 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`
      Parameters:
        `path` - The URI path of this request message.

    - #### 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`
      Parameters:
        `scheme` - The scheme of this request message.

    - #### 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`
      Parameters:
        `authority` - The authority of this request message.

    - #### setAbsoluteRequestUri

          public void setAbsoluteRequestUri(boolean absoluteRequestUri)

      Sets whether `getRequestUri()` 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.

      Parameters:
        `absoluteRequestUri` - Whether `getRequestUri()` should return the request URI in an absolute form.
      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.

    - #### 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` - Thrown when a string could not be parsed as a URI reference.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `HeaderGroup`

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.