public class HttpResponseImpl extends Object implements HttpResponse, AutoAsync<HttpResponse>
An HttpResponseImpl can be modified after construction, e.g. by header(String, String).
These mutation methods return `this` for method chaining.
Many static methods in HttpResponse return HttpResponseImpl objects,
on which the caller can make further modifications.
HttpResponseImpl is a subtype of Async<HttpResponse>;
it can be returned from HttpHandler.handle(HttpRequest);
it can be invoked with Async methods like .then().
| Constructor and Description |
|---|
HttpResponseImpl(HttpStatus status,
HttpEntity entity)
Create an http response.
|
HttpResponseImpl(HttpResponse originResponse)
Copy an http response.
|
| Instance Methods | |
|---|---|
String |
httpVersion()
Get the HTTP version.
|
HttpStatus |
status()
Get the status.
|
HeaderMap |
headers()
Get the headers.
|
ArrayList<Cookie> |
cookies()
Get the cookies.
|
HttpEntity |
entity()
Get the entity.
|
HttpResponseImpl |
status(HttpStatus status)
Set the status.
|
HttpResponseImpl |
header(String name,
String value)
Set a header.
|
HttpResponseImpl |
cookie(String name,
String value,
Duration maxAge)
Add a cookie.
|
HttpResponseImpl |
cookie(Cookie cookie)
Add a cookie.
|
HttpResponseImpl |
entity(HttpEntity entity)
Set the entity.
|
HttpResponseImpl |
entityLastModified(Instant lastModified)
Set the entity
"lastModified" property. |
HttpResponseImpl |
entityExpires(Instant expires)
Set the entity
"expires" property. |
HttpResponseImpl |
entityEtag(String etag)
Set the entity
"etag" property. |
HttpResponseImpl |
entityEtagIsWeak(boolean etagIsWeak)
Set the entity
"etagIsWeak" property. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbodyBytes, bodyString, header, statusCodecancel, isCompleted, onCompletion, pollResult, timeoutpublic HttpResponseImpl(HttpStatus status, HttpEntity entity)
public HttpResponseImpl(HttpResponse originResponse)
This can be used for response transformation, for example to add headers/cookies. The origin response is treated as read-only and will not be modified.
public String httpVersion()
httpVersion in interface HttpResponsepublic HttpStatus status()
See status(HttpStatus) for changing the status.
status in interface HttpResponsepublic HeaderMap headers()
The returned map is mutable; the response producer can manipulate it at will.
See also header(name,value).
headers in interface HttpResponsepublic ArrayList<Cookie> cookies()
The returned list is mutable; the response producer can manipulate it at will.
See also cookie(name,value,maxAge)
and cookie(Cookie).
cookies in interface HttpResponseCookieJarpublic HttpEntity entity()
See entity(HttpEntity) for changing the entity;
see entityEtag(String) etc. for modifying entity metadata.
entity in interface HttpResponsepublic HttpResponseImpl status(HttpStatus status)
public HttpResponseImpl header(String name, String value)
If value==null, the header will be removed.
public HttpResponseImpl cookie(String name, String value, Duration maxAge)
This method is equivalent to
cookie(new Cookie(name, value, maxAge)).
Note that the cookie domain=null, path="/".
See Cookie.Cookie(String, String, Duration)
and cookie(Cookie).
Example usage: resp.cookie("name","value",Cookie.SESSION)
public HttpResponseImpl cookie(Cookie cookie)
If this response already contains a cookie with the same
{domain,path,name} identity, that cookie will be removed.
public HttpResponseImpl entity(HttpEntity entity)
public HttpResponseImpl entityLastModified(Instant lastModified)
"lastModified" property.NullPointerException - if entity is nullpublic HttpResponseImpl entityExpires(Instant expires)
"expires" property.NullPointerException - if entity is nullpublic HttpResponseImpl entityEtag(String etag)
"etag" property.NullPointerException - if entity is nullpublic HttpResponseImpl entityEtagIsWeak(boolean etagIsWeak)
"etagIsWeak" property.NullPointerException - if entity is null