org.apache.hc.core5.http.message

## Class AbstractMessageWrapper<T extends HttpMessage>

- java.lang.Object
- - org.apache.hc.core5.http.message.AbstractMessageWrapper<T>

- Type Parameters:
    `T` - A `HttpMessage` type.
  All Implemented Interfaces:
    HttpMessage, MessageHeaders
  Direct Known Subclasses:
    HttpRequestWrapper, HttpResponseWrapper

      public abstract class AbstractMessageWrapper<T extends HttpMessage>
      extends Object
      implements HttpMessage

  Abstract `HttpMessage` wrapper.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractMessageWrapper(T message)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addHeader(Header header)` Adds a header to this message.
    `void` | `addHeader(String name, Object value)` Adds a header to this message.
    `boolean` | `containsHeader(String name)` Checks if a certain header is present in this message.
    `int` | `countHeaders(String name)` Checks if a certain header is present in this message and how many times.
    `Header` | `getFirstHeader(String name)` Returns the first header with a specified name of this message.
    `Header` | `getHeader(String name)` Gets single first header with the given name.
    `Header[]` | `getHeaders()` Returns all the headers of this message.
    `Header[]` | `getHeaders(String name)` Returns all the headers with a specified name of this message.
    `Header` | `getLastHeader(String name)` Returns the last header with a specified name of this message.
    `ProtocolVersion` | `getVersion()` Returns protocol version or `null` when not available.
    `Iterator<Header>` | `headerIterator()` Returns an iterator of all the headers.
    `Iterator<Header>` | `headerIterator(String name)` Returns an iterator of the headers with a given name.
    `boolean` | `removeHeader(Header header)` Removes a header from this message.
    `boolean` | `removeHeaders(String name)` Removes all headers with a certain name from this message.
    `void` | `setHeader(Header header)` Overwrites the first header with the same name.
    `void` | `setHeader(String name, Object value)` Overwrites the first header with the same name.
    `void` | `setHeaders(Header... headers)` Overwrites all the headers in the message.
    `void` | `setVersion(ProtocolVersion version)` Sets protocol version.
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### AbstractMessageWrapper

          public AbstractMessageWrapper(T message)

  - ### Method Detail

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

    - #### addHeader

          public void addHeader(Header header)

      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:
        `header` - the header to append.

    - #### 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(Header header)

      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:
        `header` - the header to set.

    - #### 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()`.

    - #### setHeaders

          public void setHeaders(Header... headers)

      Description copied from interface: `HttpMessage`
      Overwrites all the headers in the message.
      Specified by:
        `setHeaders` in interface `HttpMessage`
      Parameters:
        `headers` - the array of headers to set.

    - #### removeHeader

          public boolean removeHeader(Header header)

      Description copied from interface: `HttpMessage`
      Removes a header from this message.
      Specified by:
        `removeHeader` in interface `HttpMessage`
      Parameters:
        `header` - the header to remove.
      Returns:
        `true` if a header was removed as a result of this call.

    - #### removeHeaders

          public boolean removeHeaders(String name)

      Description copied from interface: `HttpMessage`
      Removes all headers with a certain name from this message.
      Specified by:
        `removeHeaders` in interface `HttpMessage`
      Parameters:
        `name` - The name of the headers to remove.
      Returns:
        `true` if any header was removed as a result of this call.

    - #### containsHeader

          public boolean containsHeader(String name)

      Description copied from interface: `MessageHeaders`
      Checks if a certain header is present in this message. Header values are ignored.
      Specified by:
        `containsHeader` in interface `MessageHeaders`
      Parameters:
        `name` - the header name to check for.
      Returns:
        true if at least one header with this name is present.

    - #### countHeaders

          public int countHeaders(String name)

      Description copied from interface: `MessageHeaders`
      Checks if a certain header is present in this message and how many times.
      Specified by:
        `countHeaders` in interface `MessageHeaders`
      Parameters:
        `name` - the header name to check for.
      Returns:
        number of occurrences of the header in the message.

    - #### getHeaders

          public Header[] getHeaders(String name)

      Description copied from interface: `MessageHeaders`
      Returns all the headers with a specified name of this message. Header values are ignored. Headers are ordered in the sequence they will be sent over a connection.
      Specified by:
        `getHeaders` in interface `MessageHeaders`
      Parameters:
        `name` - the name of the headers to return.
      Returns:
        the headers whose name property equals `name`.

    - #### getHeader

          public Header getHeader(String name)
                           throws ProtocolException

      Description copied from interface: `MessageHeaders`
      Gets single first header with the given name.

      Header name comparison is case insensitive.

      Specified by:
        `getHeader` in interface `MessageHeaders`
      Parameters:
        `name` - the name of the header to get
      Returns:
        the first header or `null`
      Throws:
        `ProtocolException` - in case multiple headers with the given name are found.

    - #### getFirstHeader

          public Header getFirstHeader(String name)

      Description copied from interface: `MessageHeaders`
      Returns the first header with a specified name of this message. Header values are ignored. If there is more than one matching header in the message the first element of `MessageHeaders.getHeaders(String)` is returned. If there is no matching header in the message `null` is returned.
      Specified by:
        `getFirstHeader` in interface `MessageHeaders`
      Parameters:
        `name` - the name of the header to return.
      Returns:
        the first header whose name property equals `name` or `null` if no such header could be found.

    - #### getLastHeader

          public Header getLastHeader(String name)

      Description copied from interface: `MessageHeaders`
      Returns the last header with a specified name of this message. Header values are ignored. If there is more than one matching header in the message the last element of `MessageHeaders.getHeaders(String)` is returned. If there is no matching header in the message `null` is returned.
      Specified by:
        `getLastHeader` in interface `MessageHeaders`
      Parameters:
        `name` - the name of the header to return.
      Returns:
        the last header whose name property equals `name`. or `null` if no such header could be found.

    - #### getHeaders

          public Header[] getHeaders()

      Description copied from interface: `MessageHeaders`
      Returns all the headers of this message. Headers are ordered in the sequence they will be sent over a connection.
      Specified by:
        `getHeaders` in interface `MessageHeaders`
      Returns:
        all the headers of this message

    - #### headerIterator

          public Iterator<Header> headerIterator()

      Description copied from interface: `MessageHeaders`
      Returns an iterator of all the headers.
      Specified by:
        `headerIterator` in interface `MessageHeaders`
      Returns:
        Iterator that returns Header objects in the sequence they are sent over a connection.

    - #### headerIterator

          public Iterator<Header> headerIterator(String name)

      Description copied from interface: `MessageHeaders`
      Returns an iterator of the headers with a given name.
      Specified by:
        `headerIterator` in interface `MessageHeaders`
      Parameters:
        `name` - the name of the headers over which to iterate, or `null` for all headers
      Returns:
        Iterator that returns Header objects with the argument name in the sequence they are sent over a connection.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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