Interface Response
-
- All Known Implementing Classes:
NettyResponse
public interface ResponseRepresents the asynchronous HTTP response callback for anAsyncCompletionHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classResponse.ResponseBuilder
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description StringgetContentType()Return the content-type header value.List<io.netty.handler.codec.http.cookie.Cookie>getCookies()StringgetHeader(CharSequence name)io.netty.handler.codec.http.HttpHeadersgetHeaders()List<String>getHeaders(CharSequence name)Return aListof the response header value.SocketAddressgetLocalAddress()Get the local address that the client initiated the request from.default HttpProtocolgetProtocol()Return the HTTP protocol version used for this response.SocketAddressgetRemoteAddress()Get the remote address that the client initiated the request to.StringgetResponseBody()Return the entire response body as a String.StringgetResponseBody(Charset charset)Return the entire response body as a String.io.netty.buffer.ByteBufgetResponseBodyAsByteBuf()Return the entire response body as a ByteBuf.ByteBuffergetResponseBodyAsByteBuffer()Return the entire response body as a ByteBuffer.byte[]getResponseBodyAsBytes()Return the entire response body as a byte[].default byte[]getResponseBodyAsBytesView()Returns the entire response body as a byte array whose storage the implementation may share with whatever else holds the body.InputStreamgetResponseBodyAsStream()Returns an input stream for the response body.intgetStatusCode()Returns the status code for the request.StringgetStatusText()Returns the status text for the request.UrigetUri()Return the requestUri.booleanhasResponseBody()Return true if the response's body has been computed by anAsyncHandler.booleanhasResponseHeaders()Return true if the response's headers has been computed by anAsyncHandlerIt will return false if the eitherAsyncHandler.onStatusReceived(HttpResponseStatus)orAsyncHandler.onHeadersReceived(HttpHeaders)returnedAsyncHandler.State.ABORTbooleanhasResponseStatus()Return true if the response's status has been computed by anAsyncHandlerbooleanisRedirected()Return true if the response redirects to another object.StringtoString()Subclasses SHOULD implement toString() in a way that identifies the response for logging.
-
-
-
Method Detail
-
getStatusCode
int getStatusCode()
Returns the status code for the request.- Returns:
- The status code
-
getStatusText
String getStatusText()
Returns the status text for the request.- Returns:
- The status text
-
getResponseBodyAsBytes
byte[] getResponseBodyAsBytes()
Return the entire response body as a byte[].- Returns:
- the entire response body as a byte[].
-
getResponseBodyAsBytesView
default byte[] getResponseBodyAsBytesView()
Returns the entire response body as a byte array whose storage the implementation may share with whatever else holds the body.The returned array must be treated as read-only, and the response is not its only holder. Where it is a body part's own array, it is the array reachable from the part handed to
AsyncHandler.onBodyPartReceived(org.asynchttpclient.HttpResponseBodyPart), the one eachTransferListeneris given by aTransferCompletionHandler, the oneHttpResponseBodyPart.getBodyByteBuffer()wraps for aResumableListener, and the onegetResponseBodyAsByteBuf()wraps. Writing to it changes what all of those see, and a write through any of them changes what this returns.Whether anything is shared at all is not something to rely on. It depends on how the body happened to arrive - how the origin chunked it, whether a proxy re-chunked it, whether it was compressed - on how the client happened to read it off the wire, which varies with connection age and client configuration, and on the body parts the implementation was given. The same body from the same server may be shared on one response and copied on the next. Which of the two a caller gets is the peer's choice rather than the caller's, so code that writes to the array can behave one way against a friendly server and another way against a hostile one. No array identity is guaranteed between calls either.
A caller that needs an array it may modify should copy what it receives.
getResponseBodyAsBytes()is the accessor to reach for first, but it is implemented by whoever implements this interface, so read its contract rather than assuming it hands over an array of its own.Implementation note: the default implementation of this method returns
getResponseBodyAsBytes(). An implementation that leaves that default in place must not implementgetResponseBodyAsBytes()in terms of this method, or the two call each other. Overriding both is fine.- Returns:
- the entire response body, possibly sharing storage with the response
-
getResponseBodyAsByteBuffer
ByteBuffer getResponseBodyAsByteBuffer()
Return the entire response body as a ByteBuffer.- Returns:
- the entire response body as a ByteBuffer.
-
getResponseBodyAsByteBuf
io.netty.buffer.ByteBuf getResponseBodyAsByteBuf()
Return the entire response body as a ByteBuf.- Returns:
- the entire response body as a ByteBuf.
-
getResponseBodyAsStream
InputStream getResponseBodyAsStream()
Returns an input stream for the response body. Note that you should not try to get this more than once, and that you should not close the stream.- Returns:
- The input stream
-
getResponseBody
String getResponseBody(Charset charset)
Return the entire response body as a String.- Parameters:
charset- the charset to use when decoding the stream- Returns:
- the entire response body as a String.
-
getResponseBody
String getResponseBody()
Return the entire response body as a String.- Returns:
- the entire response body as a String.
-
getUri
Uri getUri()
Return the requestUri. Note that if the request got redirected, the value of theUriwill be the last valid redirect url.- Returns:
- the request
Uri.
-
getContentType
String getContentType()
Return the content-type header value.- Returns:
- the content-type header value.
-
getHeader
String getHeader(CharSequence name)
- Parameters:
name- the header name- Returns:
- the first response header value
-
getHeaders
List<String> getHeaders(CharSequence name)
Return aListof the response header value.- Parameters:
name- the header name- Returns:
- the response header value
-
getHeaders
io.netty.handler.codec.http.HttpHeaders getHeaders()
-
isRedirected
boolean isRedirected()
Return true if the response redirects to another object.- Returns:
- True if the response redirects to another object.
-
toString
String toString()
Subclasses SHOULD implement toString() in a way that identifies the response for logging.
-
getCookies
List<io.netty.handler.codec.http.cookie.Cookie> getCookies()
- Returns:
- the list of
Cookie.
-
hasResponseStatus
boolean hasResponseStatus()
Return true if the response's status has been computed by anAsyncHandler- Returns:
- true if the response's status has been computed by an
AsyncHandler
-
hasResponseHeaders
boolean hasResponseHeaders()
Return true if the response's headers has been computed by anAsyncHandlerIt will return false if the eitherAsyncHandler.onStatusReceived(HttpResponseStatus)orAsyncHandler.onHeadersReceived(HttpHeaders)returnedAsyncHandler.State.ABORT- Returns:
- true if the response's headers has been computed by an
AsyncHandler
-
hasResponseBody
boolean hasResponseBody()
Return true if the response's body has been computed by anAsyncHandler. It will return false if:- either the
AsyncHandler.onStatusReceived(HttpResponseStatus)returnedAsyncHandler.State.ABORT - or
AsyncHandler.onHeadersReceived(HttpHeaders)returnedAsyncHandler.State.ABORT - response body was empty
- Returns:
- true if the response's body has been computed by an
AsyncHandlerto new empty bytes
- either the
-
getProtocol
default HttpProtocol getProtocol()
Return the HTTP protocol version used for this response.- Returns:
- the protocol, defaults to
HttpProtocol.HTTP_1_1
-
getRemoteAddress
SocketAddress getRemoteAddress()
Get the remote address that the client initiated the request to.- Returns:
- The remote address that the client initiated the request to. May be
nullif asynchronous provider is unable to provide the remote address
-
getLocalAddress
SocketAddress getLocalAddress()
Get the local address that the client initiated the request from.- Returns:
- The local address that the client initiated the request from. May be
nullif asynchronous provider is unable to provide the local address
-
-