Top Description Fields Constructors Methods
org.apache.hc.core5.http.message

public Class BasicHttpResponse

extends HeaderGroup
implements HttpResponse
Class Inheritance
All Implemented Interfaces
org.apache.hc.core5.http.HttpResponse, org.apache.hc.core5.http.HttpMessage, org.apache.hc.core5.http.MessageHeaders
Known Direct Subclasses
org.apache.hc.core5.http.message.BasicClassicHttpResponse
Imports
java.util.Locale, org.apache.hc.core5.http.HttpResponse, .ProtocolVersion, .ReasonPhraseCatalog, org.apache.hc.core5.http.impl.EnglishReasonPhraseCatalog, org.apache.hc.core5.util.Args, .TextUtils

Basic implementation of HttpResponse.
Since
4.0

Field Summary

Modifier and TypeField and Description
private int
private Locale
private final ReasonPhraseCatalog
private String
private static final long
private ProtocolVersion

Constructor Summary

AccessConstructor and Description
public
BasicHttpResponse(final int
the status code
code
,
final ReasonPhraseCatalog
the reason phrase catalog, or null to disable automatic reason phrase lookup
catalog
,
final Locale
the locale for looking up reason phrases, or null for the system locale
locale
)

Creates a new response.

public
BasicHttpResponse(final int
the status code of the response
code
,
final String
the reason phrase to the status code, or null
reasonPhrase
)

Creates a new response.

public
BasicHttpResponse(final int
the status code of the response
code
)

Creates a new response.

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(final String
the name of the header.
name
,
final Object
the value of the header, taken as the value's Object#toString().
value
)

Implements org.apache.hc.core5.http.HttpMessage.addHeader.

Adds a header to this message.
public int
getCode()

Implements org.apache.hc.core5.http.HttpResponse.getCode.

Obtains the code of this response message.
public Locale
getLocale()

Implements org.apache.hc.core5.http.HttpResponse.getLocale.

Obtains the locale of this response.
protected String

Returns:

the reason phrase, or null if there is none
getReason
(final int
the status code for which to look up the reason
code
)

Looks up a reason phrase.

public String
getReasonPhrase()

Implements org.apache.hc.core5.http.HttpResponse.getReasonPhrase.

Obtains the reason phrase of this response if available.
public ProtocolVersion
getVersion()

Implements org.apache.hc.core5.http.HttpMessage.getVersion.

Returns protocol version or null when not available.
public void
setCode(final int
the HTTP status code.
code
)

Implements org.apache.hc.core5.http.HttpResponse.setCode.

Updates status code of this response message.
public void
setHeader(final String
the name of the header.
name
,
final Object
the value of the header, taken as the value's Object#toString().
value
)

Implements org.apache.hc.core5.http.HttpMessage.setHeader.

Overwrites the first header with the same name.
public void
setLocale(final Locale
the new locale
locale
)

Implements org.apache.hc.core5.http.HttpResponse.setLocale.

Changes the locale of this response.
public void
setReasonPhrase(final String
the new reason phrase as a single-line string, or null to unset the reason phrase
reason
)

Implements org.apache.hc.core5.http.HttpResponse.setReasonPhrase.

Updates the status line of this response with a new reason phrase.
public void
setVersion(final ProtocolVersion version)

Implements org.apache.hc.core5.http.HttpMessage.setVersion.

Sets protocol version.
public String
toString()

Overrides org.apache.hc.core5.http.message.HeaderGroup.toString.

Returns a string representation of the object.
Inherited from org.apache.hc.core5.http.message.HeaderGroup:
addHeaderclearcontainsHeadercountHeadersgetCondensedHeadergetFirstHeadergetHeadergetHeadersgetHeadersgetLastHeaderheaderIteratorheaderIteratorremoveHeaderremoveHeadersremoveHeaderssetHeadersetHeaders

Field Detail

codeback to summary
private int code
localeback to summary
private Locale locale
reasonCatalogback to summary
private final ReasonPhraseCatalog reasonCatalog
reasonPhraseback to summary
private String reasonPhrase
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.hc.core5.http.message.HeaderGroup.serialVersionUID.

versionback to summary
private ProtocolVersion version

Constructor Detail

BasicHttpResponseback to summary
public BasicHttpResponse(final int code, final ReasonPhraseCatalog catalog, final Locale locale)

Creates a new response.

Parameters
code:int

the status code

catalog:ReasonPhraseCatalog

the reason phrase catalog, or null to disable automatic reason phrase lookup

locale:Locale

the locale for looking up reason phrases, or null for the system locale

BasicHttpResponseback to summary
public BasicHttpResponse(final int code, final String reasonPhrase)

Creates a new response.

Parameters
code:int

the status code of the response

reasonPhrase:String

the reason phrase to the status code, or null

BasicHttpResponseback to summary
public BasicHttpResponse(final int code)

Creates a new response.

Parameters
code:int

the status code of the response

Method Detail

addHeaderback to summary
public void addHeader(final String name, final Object value)

Implements org.apache.hc.core5.http.HttpMessage.addHeader.

Doc from org.apache.hc.core5.http.HttpMessage.addHeader.

Adds a header to this message. The header will be appended to the end of the list.

Parameters
name:String

the name of the header.

value:Object

the value of the header, taken as the value's Object#toString().

Annotations
@Override
getCodeback to summary
public int getCode()

Implements org.apache.hc.core5.http.HttpResponse.getCode.

Doc from org.apache.hc.core5.http.HttpResponse.getCode.

Obtains the code of this response message.

Returns:int

the status code.

Annotations
@Override
getLocaleback to summary
public Locale getLocale()

Implements org.apache.hc.core5.http.HttpResponse.getLocale.

Doc from org.apache.hc.core5.http.HttpResponse.getLocale.

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.

Returns:Locale

the locale of this response, never null

Annotations
@Override
getReasonback to summary
protected String getReason(final int code)

Looks up a reason phrase. This method evaluates the currently set catalog and locale. It also handles a missing catalog.

Parameters
code:int

the status code for which to look up the reason

Returns:String

the reason phrase, or null if there is none

getReasonPhraseback to summary
public String getReasonPhrase()

Implements org.apache.hc.core5.http.HttpResponse.getReasonPhrase.

Doc from org.apache.hc.core5.http.HttpResponse.getReasonPhrase.

Obtains the reason phrase of this response if available.

Returns:String

the reason phrase.

Annotations
@Override
getVersionback to summary
public ProtocolVersion getVersion()

Implements org.apache.hc.core5.http.HttpMessage.getVersion.

Doc from org.apache.hc.core5.http.HttpMessage.getVersion.

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.

Annotations
@Override
setCodeback to summary
public void setCode(final int code)

Implements org.apache.hc.core5.http.HttpResponse.setCode.

Doc from org.apache.hc.core5.http.HttpResponse.setCode.

Updates status code of this response message.

Parameters
code:int

the HTTP status code.

Annotations
@Override
setHeaderback to summary
public void setHeader(final String name, final Object value)

Implements org.apache.hc.core5.http.HttpMessage.setHeader.

Doc from org.apache.hc.core5.http.HttpMessage.setHeader.

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.

Parameters
name:String

the name of the header.

value:Object

the value of the header, taken as the value's Object#toString().

Annotations
@Override
setLocaleback to summary
public void setLocale(final Locale locale)

Implements org.apache.hc.core5.http.HttpResponse.setLocale.

Doc from org.apache.hc.core5.http.HttpResponse.setLocale.

Changes the locale of this response.

Parameters
locale:Locale

the new locale

Annotations
@Override
setReasonPhraseback to summary
public void setReasonPhrase(final String reason)

Implements org.apache.hc.core5.http.HttpResponse.setReasonPhrase.

Doc from org.apache.hc.core5.http.HttpResponse.setReasonPhrase.

Updates the status line of this response with a new reason phrase.

Parameters
reason:String

the new reason phrase as a single-line string, or null to unset the reason phrase

Annotations
@Override
setVersionback to summary
public void setVersion(final ProtocolVersion version)

Implements org.apache.hc.core5.http.HttpMessage.setVersion.

Doc from org.apache.hc.core5.http.HttpMessage.setVersion.

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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.apache.hc.core5.http.message.HeaderGroup.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override