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)
HttpMessage
addHeader
in interface HttpMessage
header
- the header to append.public void addHeader(String name, Object value)
HttpMessage
addHeader
in interface HttpMessage
name
- the name of the header.value
- the value of the header, taken as the value's Object.toString()
.public void close() throws IOException
Closeable
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if an I/O error occurspublic boolean containsHeader(String name)
MessageHeaders
containsHeader
in interface MessageHeaders
name
- the header name to check for.public int countHeaders(String name)
MessageHeaders
countHeaders
in interface MessageHeaders
name
- the header name to check for.public int getCode()
HttpResponse
getCode
in interface HttpResponse
public HttpEntity getEntity()
HttpEntityContainer
getEntity
in interface HttpEntityContainer
null
if not availablepublic Header getFirstHeader(String name)
MessageHeaders
MessageHeaders.getHeaders(String)
is returned.
If there is no matching header in the message null
is
returned.getFirstHeader
in interface MessageHeaders
name
- the name of the header to return.name
or null
if no such header could be found.public Header getHeader(String name) throws ProtocolException
MessageHeaders
Header name comparison is case insensitive.
getHeader
in interface MessageHeaders
name
- the name of the header to getnull
ProtocolException
- in case multiple headers with the given name are found.public Header[] getHeaders()
MessageHeaders
getHeaders
in interface MessageHeaders
public Header[] getHeaders(String name)
MessageHeaders
getHeaders
in interface MessageHeaders
name
- the name of the headers to return.name
.public Header getLastHeader(String name)
MessageHeaders
MessageHeaders.getHeaders(String)
is returned. If there is no
matching header in the message null
is returned.getLastHeader
in interface MessageHeaders
name
- the name of the header to return.name
.
or null
if no such header could be found.public java.util.Locale getLocale()
HttpResponse
status code
.
It can be changed using setLocale
.getLocale
in interface HttpResponse
null
public String getReasonPhrase()
HttpResponse
getReasonPhrase
in interface HttpResponse
public ProtocolVersion getVersion()
HttpMessage
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.
getVersion
in interface HttpMessage
public Iterator<Header> headerIterator()
MessageHeaders
headerIterator
in interface MessageHeaders
public Iterator<Header> headerIterator(String name)
MessageHeaders
headerIterator
in interface MessageHeaders
name
- the name of the headers over which to iterate, or
null
for all headerspublic boolean removeHeader(Header header)
HttpMessage
removeHeader
in interface HttpMessage
header
- the header to remove.true
if a header was removed as a result of this call.public boolean removeHeaders(String name)
HttpMessage
removeHeaders
in interface HttpMessage
name
- The name of the headers to remove.true
if any header was removed as a result of this call.public void setCode(int code)
HttpResponse
setCode
in interface HttpResponse
code
- the HTTP status code.HttpStatus
public void setEntity(HttpEntity entity)
HttpEntityContainer
Please 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 HttpEntityContainer
entity
- the entity to set of this message, or null
to unsetpublic void setHeader(Header header)
HttpMessage
setHeader
in interface HttpMessage
header
- the header to set.public void setHeader(String name, Object value)
HttpMessage
setHeader
in interface HttpMessage
name
- the name of the header.value
- the value of the header, taken as the value's Object.toString()
.public void setHeaders(Header... headers)
HttpMessage
setHeaders
in interface HttpMessage
headers
- the array of headers to set.public void setLocale(java.util.Locale loc)
HttpResponse
setLocale
in interface HttpResponse
loc
- the new localepublic void setReasonPhrase(String reason)
HttpResponse
setReasonPhrase
in interface HttpResponse
reason
- the new reason phrase as a single-line string, or
null
to unset the reason phrasepublic void setVersion(ProtocolVersion version)
HttpMessage
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.
setVersion
in interface HttpMessage
public String toString()
Object
toString
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())