@Immutable @Beta public class Response extends Object
JDisc.handleRequest(Request)
.Request
Modifier and Type | Field and Description |
---|---|
private byte[] |
body |
private static Pattern |
charsetPattern |
private Headers |
headers |
private int |
status |
Constructor and Description |
---|
Response()
Creates a Response with an empty body, and 200 (OK) response code.
|
Response(byte[] body)
Creates a Response with a message body, and 200 (OK) response code.
|
Response(int status,
byte[] body)
Creates a Response with a message body, and the given response code.
|
Modifier and Type | Method and Description |
---|---|
private Charset |
charset() |
(package private) static Charset |
charset(String contentType) |
byte[] |
getBody()
Returns the body of this Response.
|
String |
getBodyAsString()
Attempts to decode the buffer returned by
getBody() as a String in a best-effort manner. |
Headers |
getHeaders()
Returns a mutable multi-map of headers for this Response.
|
int |
getStatus()
Returns the status code of this response.
|
String |
toString() |
private static final Pattern charsetPattern
private final int status
private final Headers headers
private final byte[] body
public Response()
public Response(byte[] body)
body
- the body of the responsepublic Response(int status, byte[] body)
status
- the status code of the responsebody
- the body of the responsepublic int getStatus()
Returns the status code of this response. This is an integer result code of the attempt to understand and
satisfy the corresponding Request
.
public byte[] getBody()
public String getBodyAsString() throws CharacterCodingException
getBody()
as a String in a best-effort manner. This is done
using the Content-Type header - and defaults to UTF-8 encoding if the header is unparseable or not found.
Note that this may very well throw a CharacterCodingException
.CharacterCodingException
- if the body buffer was not well-formedpublic Headers getHeaders()
private Charset charset()
Copyright © 2018. All rights reserved.