public final class CloseableHttpResponse extends Object implements ClassicHttpResponse
| 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.
|
void |
close()
Closes this stream and releases any system resources associated with it.
|
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.
|
int |
getCode()
Obtains the code of this response message.
|
HttpEntity |
getEntity()
Obtains the message entity, if available.
|
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.
|
java.util.Locale |
getLocale()
Obtains the locale of this response.
|
String |
getReasonPhrase()
Obtains the reason phrase of this response if available.
|
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 |
setCode(int code)
Updates status code of this response message.
|
void |
setEntity(HttpEntity entity)
Sets an entity for 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 |
setLocale(java.util.Locale loc)
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()
Returns a string representation of the object.
|
public void addHeader(Header header)
HttpMessageaddHeader in interface HttpMessageheader - the header to append.public void addHeader(String name, Object value)
HttpMessageaddHeader in interface HttpMessagename - the name of the header.value - the value of the header, taken as the value's Object.toString().public void close()
throws IOException
Closeableclose in interface Closeableclose in interface AutoCloseableIOException - if an I/O error occurspublic boolean containsHeader(String name)
MessageHeaderscontainsHeader in interface MessageHeadersname - the header name to check for.public int countHeaders(String name)
MessageHeaderscountHeaders in interface MessageHeadersname - the header name to check for.public int getCode()
HttpResponsegetCode in interface HttpResponsepublic HttpEntity getEntity()
HttpEntityContainergetEntity in interface HttpEntityContainernull if not availablepublic Header getFirstHeader(String name)
MessageHeadersMessageHeaders.getHeaders(String) is returned.
If there is no matching header in the message null is
returned.getFirstHeader in interface MessageHeadersname - the name of the header to return.name
or null if no such header could be found.public Header getHeader(String name) throws ProtocolException
MessageHeadersHeader name comparison is case insensitive.
getHeader in interface MessageHeadersname - the name of the header to getnullProtocolException - in case multiple headers with the given name are found.public Header[] getHeaders()
MessageHeadersgetHeaders in interface MessageHeaderspublic Header[] getHeaders(String name)
MessageHeadersgetHeaders in interface MessageHeadersname - the name of the headers to return.name.public Header getLastHeader(String name)
MessageHeadersMessageHeaders.getHeaders(String) is returned. If there is no
matching header in the message null is returned.getLastHeader in interface MessageHeadersname - the name of the header to return.name.
or null if no such header could be found.public java.util.Locale getLocale()
HttpResponsestatus code.
It can be changed using setLocale.getLocale in interface HttpResponsenullpublic String getReasonPhrase()
HttpResponsegetReasonPhrase in interface HttpResponsepublic ProtocolVersion getVersion()
HttpMessagenull 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.
getVersion in interface HttpMessagepublic Iterator<Header> headerIterator()
MessageHeadersheaderIterator in interface MessageHeaderspublic Iterator<Header> headerIterator(String name)
MessageHeadersheaderIterator in interface MessageHeadersname - the name of the headers over which to iterate, or
null for all headerspublic boolean removeHeader(Header header)
HttpMessageremoveHeader in interface HttpMessageheader - the header to remove.true if a header was removed as a result of this call.public boolean removeHeaders(String name)
HttpMessageremoveHeaders in interface HttpMessagename - The name of the headers to remove.true if any header was removed as a result of this call.public void setCode(int code)
HttpResponsesetCode in interface HttpResponsecode - the HTTP status code.HttpStatuspublic void setEntity(HttpEntity entity)
HttpEntityContainerPlease note that if an entity has already been set it is responsibility of the caller to ensure release of the resources that may be associated with that entity.
setEntity in interface HttpEntityContainerentity - the entity to set of this message, or null to unsetpublic void setHeader(Header header)
HttpMessagesetHeader in interface HttpMessageheader - the header to set.public void setHeader(String name, Object value)
HttpMessagesetHeader in interface HttpMessagename - the name of the header.value - the value of the header, taken as the value's Object.toString().public void setHeaders(Header... headers)
HttpMessagesetHeaders in interface HttpMessageheaders - the array of headers to set.public void setLocale(java.util.Locale loc)
HttpResponsesetLocale in interface HttpResponseloc - the new localepublic void setReasonPhrase(String reason)
HttpResponsesetReasonPhrase in interface HttpResponsereason - the new reason phrase as a single-line string, or
null to unset the reason phrasepublic void setVersion(ProtocolVersion version)
HttpMessageFor 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.
setVersion in interface HttpMessagepublic String toString()
ObjecttoString method returns a
string that "textually represents" this object. The result should be a concise but informative
representation that is easy for a person to read. It is recommended that all subclasses override
this method.
The toString method for class Object returns a string consisting of the name of
the class of which the object is an instance, the at-sign character `@', and the unsigned
hexadecimal representation of the hash code of the object. In other words, this method returns a
string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())