org.apache.hc.core5.http.message

## Class BasicHttpResponse

- java.lang.Object
- - org.apache.hc.core5.http.message.HeaderGroup
  - - org.apache.hc.core5.http.message.BasicHttpResponse

- All Implemented Interfaces:
    Serializable, HttpMessage, HttpResponse, MessageHeaders
  Direct Known Subclasses:
    BasicClassicHttpResponse

      public class BasicHttpResponse
      extends HeaderGroup
      implements HttpResponse

  Basic implementation of `HttpResponse`.
  Since:
    4.0
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicHttpResponse(int code)` Creates a new response.
    `BasicHttpResponse(int code, ReasonPhraseCatalog catalog, Locale locale)` Creates a new response.
    `BasicHttpResponse(int code, String reasonPhrase)` Creates a new response.

  - ### 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.
    `int` | `getCode()` Obtains the code of this response message.
    `Locale` | `getLocale()` Obtains the locale of this response.
    `protected String` | `getReason(int code)` Looks up a reason phrase.
    `String` | `getReasonPhrase()` Obtains the reason phrase of this response if available.
    `ProtocolVersion` | `getVersion()` Returns protocol version or `null` when not available.
    `void` | `setCode(int code)` Updates status code of this response message.
    `void` | `setHeader(String name, Object value)` Overwrites the first header with the same name.
    `void` | `setLocale(Locale locale)` Changes the locale of this response.
    `void` | `setReasonPhrase(String reason)` Updates the status line of this response with a new reason phrase.
    `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

    - #### BasicHttpResponse

          public BasicHttpResponse(int code,
                                   ReasonPhraseCatalog catalog,
                                   Locale locale)

      Creates a new response.
      Parameters:
        `code` - the status code
        `catalog` - the reason phrase catalog, or `null` to disable automatic reason phrase lookup
        `locale` - the locale for looking up reason phrases, or `null` for the system locale

    - #### BasicHttpResponse

          public BasicHttpResponse(int code,
                                   String reasonPhrase)

      Creates a new response.
      Parameters:
        `code` - the status code of the response
        `reasonPhrase` - the reason phrase to the status code, or `null`

    - #### BasicHttpResponse

          public BasicHttpResponse(int code)

      Creates a new response.
      Parameters:
        `code` - the status code of the response

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

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

    - #### getCode

          public int getCode()

      Description copied from interface: `HttpResponse`
      Obtains the code of this response message.
      Specified by:
        `getCode` in interface `HttpResponse`
      Returns:
        the status code.

    - #### getLocale

          public Locale getLocale()

      Description copied from interface: `HttpResponse`
      Obtains the locale of this response. The locale is used to determine the reason phrase for the `status code`. It can be changed using `setLocale`.
      Specified by:
        `getLocale` in interface `HttpResponse`
      Returns:
        the locale of this response, never `null`

    - #### setCode

          public void setCode(int code)

      Description copied from interface: `HttpResponse`
      Updates status code of this response message.
      Specified by:
        `setCode` in interface `HttpResponse`
      Parameters:
        `code` - the HTTP status code.
      See Also:
        `HttpStatus`

    - #### getReasonPhrase

          public String getReasonPhrase()

      Description copied from interface: `HttpResponse`
      Obtains the reason phrase of this response if available.
      Specified by:
        `getReasonPhrase` in interface `HttpResponse`
      Returns:
        the reason phrase.

    - #### setReasonPhrase

          public void setReasonPhrase(String reason)

      Description copied from interface: `HttpResponse`
      Updates the status line of this response with a new reason phrase.
      Specified by:
        `setReasonPhrase` in interface `HttpResponse`
      Parameters:
        `reason` - the new reason phrase as a single-line string, or `null` to unset the reason phrase

    - #### setLocale

          public void setLocale(Locale locale)

      Description copied from interface: `HttpResponse`
      Changes the locale of this response.
      Specified by:
        `setLocale` in interface `HttpResponse`
      Parameters:
        `locale` - the new locale

    - #### getReason

          protected String getReason(int code)

      Looks up a reason phrase. This method evaluates the currently set catalog and locale. It also handles a missing catalog.
      Parameters:
        `code` - the status code for which to look up the reason
      Returns:
        the reason phrase, or `null` if there is none

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `HeaderGroup`

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