public class HttpResponse extends Action
Action.Type
logger
Constructor and Description |
---|
HttpResponse() |
Modifier and Type | Method and Description |
---|---|
HttpResponse |
applyDelay() |
HttpResponse |
clone() |
boolean |
containsHeader(String name,
String value) |
BodyWithContentType |
getBody() |
String |
getBodyAsString() |
ConnectionOptions |
getConnectionOptions() |
List<Cookie> |
getCookies() |
Delay |
getDelay() |
String |
getFirstHeader(String name) |
List<String> |
getHeader(String name) |
List<Header> |
getHeaders() |
Integer |
getStatusCode() |
Action.Type |
getType() |
static HttpResponse |
notFoundResponse()
Static builder to create a not found response.
|
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 |
updateHeader(Header header)
Update header to return as a Header object, if a header with
the same name already exists it will be modified
|
HttpResponse |
updateHeader(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
|
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 |
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(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(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(List<Header> headers)
The headers to return as a list of Header objects
|
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
addFieldsExcludedFromEqualsAndHashCode, equals, fieldsExcludedFromEqualsAndHashCode, hashCode
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 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(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 HttpResponse withHeaders(List<Header> headers)
headers
- a list of Header objectspublic HttpResponse withHeaders(Header... headers)
headers
- a varargs of Header objectspublic HttpResponse withHeader(Header header)
header
- a Header objectspublic HttpResponse withHeader(String name, String... values)
name
- the header namevalues
- the header values which can be a varags of strings or regular expressionspublic HttpResponse updateHeader(Header header)
header
- a Header objectspublic HttpResponse updateHeader(String name, String... values)
name
- the header namevalues
- the header values which can be a varags of strings or regular expressionspublic 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 value which can be a string or regular expressionpublic 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 HttpResponse applyDelay()
public Action.Type getType()
public HttpResponse clone()
Copyright © 2018. All rights reserved.