Package 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:
java.io.Serializable,HttpMessage,HttpResponse,MessageHeaders
- Direct Known Subclasses:
BasicClassicHttpResponse
public class BasicHttpResponse extends HeaderGroup implements HttpResponse
Basic implementation ofHttpResponse.- Since:
- 4.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private intcodeprivate java.util.Localelocaleprivate ReasonPhraseCatalogreasonCatalogprivate java.lang.StringreasonPhraseprivate static longserialVersionUIDprivate ProtocolVersionversion
-
Constructor Summary
Constructors Constructor Description BasicHttpResponse(int code)Creates a new response.BasicHttpResponse(int code, java.lang.String reasonPhrase)Creates a new response.BasicHttpResponse(int code, ReasonPhraseCatalog catalog, java.util.Locale locale)Creates a new response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.Object value)Adds a header to this message.intgetCode()Obtains the code of this response message.java.util.LocalegetLocale()Obtains the locale of this response.protected java.lang.StringgetReason(int code)Looks up a reason phrase.java.lang.StringgetReasonPhrase()Obtains the reason phrase of this response if available.ProtocolVersiongetVersion()Returns protocol version ornullwhen not available.voidsetCode(int code)Updates status code of this response message.voidsetHeader(java.lang.String name, java.lang.Object value)Overwrites the first header with the same name.voidsetLocale(java.util.Locale locale)Changes the locale of this response.voidsetReasonPhrase(java.lang.String reason)Updates the status line of this response with a new reason phrase.voidsetVersion(ProtocolVersion version)Sets protocol version.java.lang.StringtoString()-
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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
reasonCatalog
private final ReasonPhraseCatalog reasonCatalog
-
version
private ProtocolVersion version
-
locale
private java.util.Locale locale
-
code
private int code
-
reasonPhrase
private java.lang.String reasonPhrase
-
-
Constructor Detail
-
BasicHttpResponse
public BasicHttpResponse(int code, ReasonPhraseCatalog catalog, java.util.Locale locale)Creates a new response.- Parameters:
code- the status codecatalog- the reason phrase catalog, ornullto disable automatic reason phrase lookuplocale- the locale for looking up reason phrases, ornullfor the system locale
-
BasicHttpResponse
public BasicHttpResponse(int code, java.lang.String reasonPhrase)Creates a new response.- Parameters:
code- the status code of the responsereasonPhrase- the reason phrase to the status code, ornull
-
BasicHttpResponse
public BasicHttpResponse(int code)
Creates a new response.- Parameters:
code- the status code of the response
-
-
Method Detail
-
addHeader
public void addHeader(java.lang.String name, java.lang.Object value)Description copied from interface:HttpMessageAdds a header to this message. The header will be appended to the end of the list.- Specified by:
addHeaderin interfaceHttpMessage- Parameters:
name- the name of the header.value- the value of the header, taken as the value'sObject.toString().
-
setHeader
public void setHeader(java.lang.String name, java.lang.Object value)Description copied from interface:HttpMessageOverwrites 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:
setHeaderin interfaceHttpMessage- Parameters:
name- the name of the header.value- the value of the header, taken as the value'sObject.toString().
-
setVersion
public void setVersion(ProtocolVersion version)
Description copied from interface:HttpMessageSets 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:
setVersionin interfaceHttpMessage
-
getVersion
public ProtocolVersion getVersion()
Description copied from interface:HttpMessageReturns protocol version ornullwhen 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:
getVersionin interfaceHttpMessage
-
getCode
public int getCode()
Description copied from interface:HttpResponseObtains the code of this response message.- Specified by:
getCodein interfaceHttpResponse- Returns:
- the status code.
-
getLocale
public java.util.Locale getLocale()
Description copied from interface:HttpResponseObtains the locale of this response. The locale is used to determine the reason phrase for thestatus code. It can be changed usingsetLocale.- Specified by:
getLocalein interfaceHttpResponse- Returns:
- the locale of this response, never
null
-
setCode
public void setCode(int code)
Description copied from interface:HttpResponseUpdates status code of this response message.- Specified by:
setCodein interfaceHttpResponse- Parameters:
code- the HTTP status code.- See Also:
HttpStatus
-
getReasonPhrase
public java.lang.String getReasonPhrase()
Description copied from interface:HttpResponseObtains the reason phrase of this response if available.- Specified by:
getReasonPhrasein interfaceHttpResponse- Returns:
- the reason phrase.
-
setReasonPhrase
public void setReasonPhrase(java.lang.String reason)
Description copied from interface:HttpResponseUpdates the status line of this response with a new reason phrase.- Specified by:
setReasonPhrasein interfaceHttpResponse- Parameters:
reason- the new reason phrase as a single-line string, ornullto unset the reason phrase
-
setLocale
public void setLocale(java.util.Locale locale)
Description copied from interface:HttpResponseChanges the locale of this response.- Specified by:
setLocalein interfaceHttpResponse- Parameters:
locale- the new locale
-
getReason
protected java.lang.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
nullif there is none
-
toString
public java.lang.String toString()
- Overrides:
toStringin classHeaderGroup
-
-