Package org.attribyte.api.http
Class ResponseBuilder
java.lang.Object
org.attribyte.api.http.ResponseBuilder
Builds immutable HTTP responses.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a response builder.ResponseBuilder(int statusCode) Creates a response builder with a response code.ResponseBuilder(int statusCode, byte[] body) Creates a response builder with a response code and body as bytes.ResponseBuilder(int statusCode, com.google.common.io.ByteSource bodySource) Creates a response builder with a response code and body as aByteSource.ResponseBuilder(int statusCode, String body) Creates a response builder with a response code and body as a string. -
Method Summary
Modifier and TypeMethodDescriptionaddAttribute(String name, Object object) Adds an attribute.addAttributes(Map<String, Object> attributes) Adds a map of attributes.Adds a header.addHeaders(Map<?, ?> headerMap) Adds a map of headers.create()Creates an immutable response.Creates an immutable streamed response.putHeaders(Collection<Header> headers) Adds a collection of headers.setBody(byte[] body) Sets the response body bytes.setBody(com.google.common.io.ByteSource body) Sets aByteSourcefor the response body.Sets the response body as a UTF-8 string.setCookies(Collection<Cookie> cookies) Sets cookies.Sets request/response stats.setStatusCode(int statusCode) Sets the response code.
-
Constructor Details
-
ResponseBuilder
public ResponseBuilder()Creates a response builder. -
ResponseBuilder
public ResponseBuilder(int statusCode) Creates a response builder with a response code.- Parameters:
statusCode- The response code.
-
ResponseBuilder
public ResponseBuilder(int statusCode, byte[] body) Creates a response builder with a response code and body as bytes.- Parameters:
statusCode- The response code.body- The response body.
-
ResponseBuilder
Creates a response builder with a response code and body as a string.- Parameters:
statusCode- The response code.body- The response body.
-
ResponseBuilder
public ResponseBuilder(int statusCode, com.google.common.io.ByteSource bodySource) Creates a response builder with a response code and body as aByteSource.- Parameters:
statusCode- The response code.bodySource- The response body source.
-
-
Method Details
-
setStatusCode
Sets the response code.- Parameters:
statusCode- The response code.- Returns:
- A self-reference.
-
setBody
Sets the response body bytes.- Parameters:
body- The body.- Returns:
- A self-reference.
-
setBody
Sets the response body as a UTF-8 string.- Parameters:
body- The body.- Returns:
- A self-reference.
-
setBody
Sets aByteSourcefor the response body.- Parameters:
body- The body byte source.- Returns:
- A self-reference.
-
create
Creates an immutable response.- Returns:
- The response.
-
createStreamed
Creates an immutable streamed response.- Returns:
- The response.
-
addHeader
Adds a header.- Parameters:
name- The header name.value- The header value.- Returns:
- A self-reference.
-
putHeaders
Adds a collection of headers.- Parameters:
headers- The headers to add.- Returns:
- A self-reference.
-
addHeaders
Adds a map of headers.- Parameters:
headerMap- The map of headers.- Returns:
- A self-reference.
-
addAttribute
Adds an attribute.- Parameters:
name- The attribute name.object- The attribute value.- Returns:
- A self-reference.
-
addAttributes
Adds a map of attributes.- Parameters:
attributes- The map of attributes.- Returns:
- A self-reference.
-
setStats
Sets request/response stats.- Parameters:
stats- The stats.- Returns:
- A self-reference.
-
setCookies
Sets cookies.- Parameters:
cookies- A collection of cookies.- Returns:
- A self-reference.
-