public class HttpResponse extends Action<HttpResponse> implements HttpMessage<HttpResponse,BodyWithContentType>
Action.Direction, 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
|
boolean |
cookieHeadeDoesNotAlreadyExists(Cookie cookieValue) |
boolean |
cookieHeadeDoesNotAlreadyExists(String name,
String value) |
boolean |
equals(Object o) |
BodyWithContentType |
getBody() |
byte[] |
getBodyAsRawBytes() |
String |
getBodyAsString() |
ConnectionOptions |
getConnectionOptions() |
List<Cookie> |
getCookieList() |
Map<NottableString,NottableString> |
getCookieMap() |
Cookies |
getCookies() |
String |
getFirstHeader(String name) |
List<String> |
getHeader(String name) |
List<Header> |
getHeaderList() |
com.google.common.collect.Multimap<NottableString,NottableString> |
getHeaderMultimap() |
Headers |
getHeaders() |
String |
getReasonPhrase() |
Integer |
getStatusCode() |
Action.Type |
getType() |
int |
hashCode() |
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 |
shallowClone() |
HttpResponse |
update(HttpResponse responseOverride,
HttpResponseModifier responseModifier) |
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,
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 |
withContentType(MediaType mediaType) |
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/8/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 |
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(NottableString name,
NottableString... 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 |
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
|
getDelay, getExpectationId, setExpectationId, withDelay, withDelay
toString
fieldsExcludedFromEqualsAndHashCode
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)
.withBody
in interface HttpMessage<HttpResponse,BodyWithContentType>
body
- a stringpublic HttpResponse withBody(String body, Charset charset)
withBody
in interface HttpMessage<HttpResponse,BodyWithContentType>
body
- a stringcharset
- character set the string will be encoded inpublic HttpResponse withBody(String body, MediaType contentType)
body
- a stringcontentType
- media type, if charset is included this will be used for encoding stringpublic HttpResponse withBody(byte[] body)
withBody
in interface HttpMessage<HttpResponse,BodyWithContentType>
body
- a byte arraypublic HttpResponse withBody(BodyWithContentType body)
withBody
in interface HttpMessage<HttpResponse,BodyWithContentType>
body
- an instance of one of the Body subclasses including StringBody or BinaryBodypublic BodyWithContentType getBody()
getBody
in interface HttpMessage<HttpResponse,BodyWithContentType>
public byte[] getBodyAsRawBytes()
getBodyAsRawBytes
in interface HttpMessage<HttpResponse,BodyWithContentType>
public String getBodyAsString()
getBodyAsString
in interface HttpMessage<HttpResponse,BodyWithContentType>
public Headers getHeaders()
getHeaders
in interface HttpMessage<HttpResponse,BodyWithContentType>
public HttpResponse withHeaders(Headers headers)
withHeaders
in interface HttpMessage<HttpResponse,BodyWithContentType>
public HttpResponse withHeaders(List<Header> headers)
withHeaders
in interface HttpMessage<HttpResponse,BodyWithContentType>
headers
- a list of Header objectspublic HttpResponse withHeaders(Header... headers)
withHeaders
in interface HttpMessage<HttpResponse,BodyWithContentType>
headers
- varargs of Header objectspublic HttpResponse withHeader(Header header)
withHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
header
- a Header objectpublic HttpResponse withHeader(String name, String... values)
withHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
name
- the header namevalues
- the header valuespublic HttpResponse withHeader(NottableString name, NottableString... values)
withHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
name
- the header name as a NottableStringvalues
- the header values which can be a varags of NottableStringspublic HttpResponse withContentType(MediaType mediaType)
withContentType
in interface HttpMessage<HttpResponse,BodyWithContentType>
public HttpResponse replaceHeader(Header header)
replaceHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
header
- a Header objectpublic HttpResponse replaceHeader(String name, String... values)
name
- the header namevalues
- the header valuespublic List<Header> getHeaderList()
getHeaderList
in interface HttpMessage<HttpResponse,BodyWithContentType>
public com.google.common.collect.Multimap<NottableString,NottableString> getHeaderMultimap()
public List<String> getHeader(String name)
getHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
public String getFirstHeader(String name)
getFirstHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
public boolean containsHeader(String name)
containsHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
name
- the header namepublic HttpResponse removeHeader(String name)
removeHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
public HttpResponse removeHeader(NottableString name)
removeHeader
in interface HttpMessage<HttpResponse,BodyWithContentType>
public boolean containsHeader(String name, String value)
name
- the header namevalue
- the header valuepublic Cookies getCookies()
getCookies
in interface HttpMessage<HttpResponse,BodyWithContentType>
public HttpResponse withCookies(Cookies cookies)
withCookies
in interface HttpMessage<HttpResponse,BodyWithContentType>
public HttpResponse withCookies(List<Cookie> cookies)
withCookies
in interface HttpMessage<HttpResponse,BodyWithContentType>
cookies
- a list of Cookie objectspublic HttpResponse withCookies(Cookie... cookies)
withCookies
in interface HttpMessage<HttpResponse,BodyWithContentType>
cookies
- a varargs of Cookie objectspublic HttpResponse withCookie(Cookie cookie)
withCookie
in interface HttpMessage<HttpResponse,BodyWithContentType>
cookie
- a Cookie objectpublic HttpResponse withCookie(String name, String value)
withCookie
in interface HttpMessage<HttpResponse,BodyWithContentType>
name
- the cookies namevalue
- the cookies valuepublic HttpResponse withCookie(NottableString name, NottableString value)
withCookie
in interface HttpMessage<HttpResponse,BodyWithContentType>
name
- the cookies namevalue
- the cookies valuepublic List<Cookie> getCookieList()
getCookieList
in interface HttpMessage<HttpResponse,BodyWithContentType>
public Map<NottableString,NottableString> getCookieMap()
public boolean cookieHeadeDoesNotAlreadyExists(Cookie cookieValue)
public boolean cookieHeadeDoesNotAlreadyExists(String name, String value)
public HttpResponse withConnectionOptions(ConnectionOptions connectionOptions)
connectionOptions
- the connection options for override the default connection behaviourpublic ConnectionOptions getConnectionOptions()
public Action.Type getType()
getType
in class Action<HttpResponse>
public HttpResponse shallowClone()
public HttpResponse clone()
public HttpResponse update(HttpResponse responseOverride, HttpResponseModifier responseModifier)
public boolean equals(Object o)
equals
in class Action<HttpResponse>
public int hashCode()
hashCode
in class Action<HttpResponse>
Copyright © 2022. All rights reserved.