public class HttpResponse extends Action
Action.Type
Constructor and Description |
---|
HttpResponse() |
Modifier and Type | Method and Description |
---|---|
HttpResponse |
clone() |
boolean |
containsHeader(String name)
Returns true if a header with the specified name has been added
|
boolean |
containsHeader(String name,
String value)
Returns true if a header with the specified name has been added
|
BodyWithContentType |
getBody() |
String |
getBodyAsString() |
ConnectionOptions |
getConnectionOptions() |
List<Cookie> |
getCookieList() |
Cookies |
getCookies() |
Delay |
getDelay() |
String |
getFirstHeader(String name) |
List<String> |
getHeader(String name) |
List<Header> |
getHeaderList() |
Headers |
getHeaders() |
String |
getReasonPhrase() |
Integer |
getStatusCode() |
Action.Type |
getType() |
static HttpResponse |
notFoundResponse()
Static builder to create a not found response.
|
HttpResponse |
removeHeader(NottableString name) |
HttpResponse |
removeHeader(String name) |
HttpResponse |
replaceHeader(Header header)
Update header to return as a Header object, if a header with
the same name already exists it will be modified
|
HttpResponse |
replaceHeader(String name,
String... values)
Update header to return as a Header object, if a header with
the same name already exists it will be modified
|
static HttpResponse |
response()
Static builder to create a response.
|
static HttpResponse |
response(String body)
Static builder to create a response with a 200 status code and the string response body.
|
HttpResponse |
withBody(BodyWithContentType body)
Set the body to return for example:
string body:
- exact(" a simple string body");
or
- new StringBody(" | a simple string body")
binary body:
- binary(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
or
- new BinaryBody(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
HttpResponse |
withBody(byte[] body)
Set response body to return as binary such as a pdf or image
|
HttpResponse |
withBody(String body)
Set response body to return as a string response body.
|
HttpResponse |
withBody(String body,
Charset charset)
Set response body to return a string response body with the specified encoding.
|
HttpResponse |
withBody(String body,
com.google.common.net.MediaType contentType)
Set response body to return a string response body with the specified encoding.
|
HttpResponse |
withConnectionOptions(ConnectionOptions connectionOptions)
The connection options for override the default connection behaviour, this allows full control of headers such
as "Connection" or "Content-Length" or controlling whether the socket is closed after the response has been sent
|
HttpResponse |
withCookie(Cookie cookie)
Add cookie to return as Set-Cookie header
|
HttpResponse |
withCookie(NottableString name,
NottableString value)
Adds one cookie to match on or to not match on using the NottableString, each NottableString can either be a positive matching value,
such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString
can be a plain string or a regex (for more details of the supported regex syntax see
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpResponse |
withCookie(String name,
String value)
Add cookie to return as Set-Cookie header
|
HttpResponse |
withCookies(Cookie... cookies)
The cookies to return as Set-Cookie headers as a varargs of Cookie objects
|
HttpResponse |
withCookies(Cookies cookies) |
HttpResponse |
withCookies(List<Cookie> cookies)
The cookies to return as Set-Cookie headers as a list of Cookie objects
|
HttpResponse |
withDelay(Delay delay)
The delay before responding with this request as a Delay object, for example new Delay(TimeUnit.SECONDS, 3)
|
HttpResponse |
withDelay(TimeUnit timeUnit,
long value)
The delay before responding with this request as a Delay object, for example new Delay(TimeUnit.SECONDS, 3)
|
HttpResponse |
withHeader(Header header)
Add a header to return as a Header object, if a header with
the same name already exists this will NOT be modified but
two headers will exist
|
HttpResponse |
withHeader(String name,
String... values)
Add a header to return as a Header object, if a header with
the same name already exists this will NOT be modified but
two headers will exist
|
HttpResponse |
withHeaders(Header... headers)
The headers to return as a varargs of Header objects
|
HttpResponse |
withHeaders(Headers headers) |
HttpResponse |
withHeaders(List<Header> headers)
The headers to return as a list of Header objects
|
HttpResponse |
withReasonPhrase(String reasonPhrase)
The reason phrase to return, if no reason code is returned this will
be defaulted to the standard reason phrase for the statusCode,
i.e.
|
HttpResponse |
withStatusCode(Integer statusCode)
The status code to return, such as 200, 404, the status code specified
here will result in the default status message for this status code for
example for 200 the status message "OK" is used
|
toString
equals, fieldsExcludedFromEqualsAndHashCode, hashCode, key
public static HttpResponse response()
public static HttpResponse response(String body)
body
- a stringpublic static HttpResponse notFoundResponse()
public HttpResponse withStatusCode(Integer statusCode)
statusCode
- an integer such as 200 or 404public Integer getStatusCode()
public HttpResponse withReasonPhrase(String reasonPhrase)
reasonPhrase
- an string such as "Not Found" or "OK"public String getReasonPhrase()
public HttpResponse withBody(String body)
withBody(String, Charset)
.body
- a stringpublic HttpResponse withBody(String body, Charset charset)
body
- a stringcharset
- character set the string will be encoded inpublic HttpResponse withBody(String body, com.google.common.net.MediaType contentType)
body
- a stringcontentType
- media type, if charset is included this will be used for encoding stringpublic HttpResponse withBody(byte[] body)
body
- a byte arraypublic HttpResponse withBody(BodyWithContentType body)
body
- an instance of one of the Body subclasses including StringBody or BinaryBodypublic BodyWithContentType getBody()
public String getBodyAsString()
public Headers getHeaders()
public HttpResponse withHeaders(Headers headers)
public HttpResponse withHeaders(List<Header> headers)
headers
- a list of Header objectspublic HttpResponse withHeaders(Header... headers)
headers
- varargs of Header objectspublic HttpResponse withHeader(Header header)
header
- a Header objectpublic HttpResponse withHeader(String name, String... values)
name
- the header namevalues
- the header valuespublic HttpResponse replaceHeader(Header header)
header
- a Header objectpublic HttpResponse replaceHeader(String name, String... values)
name
- the header namevalues
- the header valuespublic boolean containsHeader(String name)
name
- the header namepublic HttpResponse removeHeader(String name)
public HttpResponse removeHeader(NottableString name)
public Cookies getCookies()
public HttpResponse withCookies(Cookies cookies)
public boolean containsHeader(String name, String value)
name
- the header namevalue
- the header valuepublic HttpResponse withCookies(List<Cookie> cookies)
cookies
- a list of Cookie objectspublic HttpResponse withCookies(Cookie... cookies)
cookies
- a varargs of Cookie objectspublic HttpResponse withCookie(Cookie cookie)
cookie
- a Cookie objectpublic HttpResponse withCookie(String name, String value)
name
- the cookies namevalue
- the cookies valuepublic HttpResponse withCookie(NottableString name, NottableString value)
name
- the cookies namevalue
- the cookies valuepublic HttpResponse withDelay(Delay delay)
delay
- a Delay object, for example new Delay(TimeUnit.SECONDS, 3)public HttpResponse withDelay(TimeUnit timeUnit, long value)
timeUnit
- a the time unit, for example TimeUnit.SECONDSvalue
- a the number of time units to delay the responsepublic Delay getDelay()
public HttpResponse withConnectionOptions(ConnectionOptions connectionOptions)
connectionOptions
- the connection options for override the default connection behaviourpublic ConnectionOptions getConnectionOptions()
public Action.Type getType()
public HttpResponse clone()
Copyright © 2018. All rights reserved.