Class NettyResponse
- java.lang.Object
-
- org.asynchttpclient.netty.NettyResponse
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.asynchttpclient.Response
Response.ResponseBuilder
-
-
Constructor Summary
Constructors Constructor Description NettyResponse(HttpResponseStatus status, io.netty.handler.codec.http.HttpHeaders headers, List<HttpResponseBodyPart> bodyParts)
-
Method Summary
All Methods Instance Methods Concrete 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.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[].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.
-
-
-
Constructor Detail
-
NettyResponse
public NettyResponse(HttpResponseStatus status, io.netty.handler.codec.http.HttpHeaders headers, List<HttpResponseBodyPart> bodyParts)
-
-
Method Detail
-
getStatusCode
public final int getStatusCode()
Description copied from interface:ResponseReturns the status code for the request.- Specified by:
getStatusCodein interfaceResponse- Returns:
- The status code
-
getStatusText
public final String getStatusText()
Description copied from interface:ResponseReturns the status text for the request.- Specified by:
getStatusTextin interfaceResponse- Returns:
- The status text
-
getRemoteAddress
public SocketAddress getRemoteAddress()
Description copied from interface:ResponseGet the remote address that the client initiated the request to.- Specified by:
getRemoteAddressin interfaceResponse- Returns:
- The remote address that the client initiated the request to. May be
nullif asynchronous provider is unable to provide the remote address
-
getLocalAddress
public SocketAddress getLocalAddress()
Description copied from interface:ResponseGet the local address that the client initiated the request from.- Specified by:
getLocalAddressin interfaceResponse- Returns:
- The local address that the client initiated the request from. May be
nullif asynchronous provider is unable to provide the local address
-
getContentType
public final String getContentType()
Description copied from interface:ResponseReturn the content-type header value.- Specified by:
getContentTypein interfaceResponse- Returns:
- the content-type header value.
-
getHeader
public final String getHeader(CharSequence name)
-
getHeaders
public final List<String> getHeaders(CharSequence name)
Description copied from interface:ResponseReturn aListof the response header value.- Specified by:
getHeadersin interfaceResponse- Parameters:
name- the header name- Returns:
- the response header value
-
getHeaders
public final io.netty.handler.codec.http.HttpHeaders getHeaders()
- Specified by:
getHeadersin interfaceResponse
-
isRedirected
public final boolean isRedirected()
Description copied from interface:ResponseReturn true if the response redirects to another object.- Specified by:
isRedirectedin interfaceResponse- Returns:
- True if the response redirects to another object.
-
getCookies
public List<io.netty.handler.codec.http.cookie.Cookie> getCookies()
- Specified by:
getCookiesin interfaceResponse- Returns:
- the list of
Cookie.
-
getProtocol
public HttpProtocol getProtocol()
Description copied from interface:ResponseReturn the HTTP protocol version used for this response.- Specified by:
getProtocolin interfaceResponse- Returns:
- the protocol, defaults to
HttpProtocol.HTTP_1_1
-
hasResponseStatus
public boolean hasResponseStatus()
Description copied from interface:ResponseReturn true if the response's status has been computed by anAsyncHandler- Specified by:
hasResponseStatusin interfaceResponse- Returns:
- true if the response's status has been computed by an
AsyncHandler
-
hasResponseHeaders
public boolean hasResponseHeaders()
Description copied from interface:ResponseReturn 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- Specified by:
hasResponseHeadersin interfaceResponse- Returns:
- true if the response's headers has been computed by an
AsyncHandler
-
hasResponseBody
public boolean hasResponseBody()
Description copied from interface:ResponseReturn 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
- Specified by:
hasResponseBodyin interfaceResponse- Returns:
- true if the response's body has been computed by an
AsyncHandlerto new empty bytes
- either the
-
getResponseBodyAsBytes
public byte[] getResponseBodyAsBytes()
Description copied from interface:ResponseReturn the entire response body as a byte[].- Specified by:
getResponseBodyAsBytesin interfaceResponse- Returns:
- the entire response body as a byte[].
-
getResponseBodyAsBytesView
public 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 oneResponse.getResponseBodyAsByteBuf()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.
Response.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
Response.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 a lone body part's array; concatenates into one of its own when there are several, or an empty array when there are none. Which of those a given response takes is not a property of the body: see
Response.getResponseBodyAsBytesView(), whose contract is deliberately weaker than this.Whether a lone part hands over storage of its own is the part's business rather than this response's.
EagerResponseBodyPartreturns the array it holds;LazyResponseBodyPartcopies out of its buffer on every call, so a response made of lazy parts never shares whatever this says.- Specified by:
getResponseBodyAsBytesViewin interfaceResponse- Returns:
- the entire response body, possibly sharing storage with the response
-
getResponseBodyAsByteBuffer
public ByteBuffer getResponseBodyAsByteBuffer()
Description copied from interface:ResponseReturn the entire response body as a ByteBuffer.- Specified by:
getResponseBodyAsByteBufferin interfaceResponse- Returns:
- the entire response body as a ByteBuffer.
-
getResponseBodyAsByteBuf
public io.netty.buffer.ByteBuf getResponseBodyAsByteBuf()
Description copied from interface:ResponseReturn the entire response body as a ByteBuf.- Specified by:
getResponseBodyAsByteBufin interfaceResponse- Returns:
- the entire response body as a ByteBuf.
-
getResponseBody
public String getResponseBody()
Description copied from interface:ResponseReturn the entire response body as a String.- Specified by:
getResponseBodyin interfaceResponse- Returns:
- the entire response body as a String.
-
getResponseBody
public String getResponseBody(Charset charset)
Description copied from interface:ResponseReturn the entire response body as a String.- Specified by:
getResponseBodyin interfaceResponse- Parameters:
charset- the charset to use when decoding the stream- Returns:
- the entire response body as a String.
-
getResponseBodyAsStream
public InputStream getResponseBodyAsStream()
Description copied from interface:ResponseReturns 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.- Specified by:
getResponseBodyAsStreamin interfaceResponse- Returns:
- The input stream
-
-