Package org.attribyte.api.http
Class Response
java.lang.Object
org.attribyte.api.http.Response
- Direct Known Subclasses:
BodyResponse,StreamedResponse
An immutable HTTP response.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String name) Gets an attribute.<T> TgetAttribute(String name, T defaultValue) Gets an attribute with a default value.com.google.protobuf.ByteStringgetBody()Gets the response body as an immutableByteString.getCharset(String defaultCharset) Gets the charset specified for this response or the default charset if none specified.Gets the value of theContent-Typeheader.Gets all headers.getHeaderValue(String name) Gets the first header value.com.google.common.collect.ImmutableList<String> getHeaderValueList(String name) Gets an immutable list of values for a header.String[]getHeaderValues(String name) Gets all values for a header.getStats()Gets the stats, if available.intGets the HTTP response code.Deprecated.toString()
-
Field Details
-
statusCode
public final int statusCodeThe status code. -
headers
An immutable map of headers.The keys in this map are lower-case.
-
attributes
An immutable map of attributes.Beware: The values may not be immutable.
-
cookies
An immutable list of cookies. -
stats
The full stats, if any.
-
-
Constructor Details
-
Response
Creates a response.- Parameters:
statusCode- The HTTP response status code.headers- The response headers.
-
Response
Creates a response with attributes.- Parameters:
statusCode- The HTTP response status code.headers- The response headers.attributes- The attributes.
-
Response
Creates a response with attributes and stats.- Parameters:
statusCode- The HTTP response status code.headers- The response headers.attributes- The attributes.stats- Stats associated with the response.
-
Response
public Response(int statusCode, Map<?, ?> headers, Map<String, Object> attributes, Stats stats, Collection<Cookie> cookies) Creates a response with attributes, stats and cookies.- Parameters:
statusCode- The HTTP response status code.headers- The response headers.attributes- The attributes.stats- The stats associated with the response.cookies- A collection of cookies.
-
-
Method Details
-
getStatusCode
public int getStatusCode()Gets the HTTP response code.- Returns:
- The response code.
-
getBody
Gets the response body as an immutableByteString.- Returns:
- The response body, or
nullif none. - Throws:
IOException- if the body is streamed and an input error occurs.
-
getHeaderValue
Gets the first header value.- Parameters:
name- The header name.- Returns:
- The value or
nullif none.
-
getHeaderValues
Gets all values for a header.- Parameters:
name- The header name.- Returns:
- The values or
nullif none.
-
getHeaderValueList
Gets an immutable list of values for a header.- Parameters:
name- The header name.- Returns:
- The values or
nullif none.
-
getContentType
Gets the value of theContent-Typeheader.- Returns:
- The content type, or
nullif none.
-
getCharset
Gets the charset specified for this response or the default charset if none specified.- Parameters:
defaultCharset- The default charset.- Returns:
- The charset.
-
getHeaders
Gets all headers.- Returns:
- An immutable collection of headers.
-
getAttribute
Gets an attribute.- Parameters:
name- The attribute name.- Returns:
- The attribute or
nullif none set.
-
getAttribute
Gets an attribute with a default value.- Type Parameters:
T- The expected type.- Parameters:
name- The name.defaultValue- The default value.- Returns:
- The variable or
null.
-
getTiming
Deprecated.Gets the request/response timing, if available.- Returns:
- The timing or
nullif none set. - See Also:
-
getStats
Gets the stats, if available.- Returns:
- The stats or
nullif none set.
-
toString
-