Class NettyResponse

    • Method Detail

      • getStatusCode

        public final int getStatusCode()
        Description copied from interface: Response
        Returns the status code for the request.
        Specified by:
        getStatusCode in interface Response
        Returns:
        The status code
      • getStatusText

        public final String getStatusText()
        Description copied from interface: Response
        Returns the status text for the request.
        Specified by:
        getStatusText in interface Response
        Returns:
        The status text
      • getUri

        public final Uri getUri()
        Description copied from interface: Response
        Return the request Uri. Note that if the request got redirected, the value of the Uri will be the last valid redirect url.
        Specified by:
        getUri in interface Response
        Returns:
        the request Uri.
      • getRemoteAddress

        public SocketAddress getRemoteAddress()
        Description copied from interface: Response
        Get the remote address that the client initiated the request to.
        Specified by:
        getRemoteAddress in interface Response
        Returns:
        The remote address that the client initiated the request to. May be null if asynchronous provider is unable to provide the remote address
      • getLocalAddress

        public SocketAddress getLocalAddress()
        Description copied from interface: Response
        Get the local address that the client initiated the request from.
        Specified by:
        getLocalAddress in interface Response
        Returns:
        The local address that the client initiated the request from. May be null if asynchronous provider is unable to provide the local address
      • getContentType

        public final String getContentType()
        Description copied from interface: Response
        Return the content-type header value.
        Specified by:
        getContentType in interface Response
        Returns:
        the content-type header value.
      • getHeader

        public final String getHeader​(CharSequence name)
        Specified by:
        getHeader in interface Response
        Parameters:
        name - the header name
        Returns:
        the first response header value
      • getHeaders

        public final List<String> getHeaders​(CharSequence name)
        Description copied from interface: Response
        Return a List of the response header value.
        Specified by:
        getHeaders in interface Response
        Parameters:
        name - the header name
        Returns:
        the response header value
      • getHeaders

        public final io.netty.handler.codec.http.HttpHeaders getHeaders()
        Specified by:
        getHeaders in interface Response
      • isRedirected

        public final boolean isRedirected()
        Description copied from interface: Response
        Return true if the response redirects to another object.
        Specified by:
        isRedirected in interface Response
        Returns:
        True if the response redirects to another object.
      • getCookies

        public List<io.netty.handler.codec.http.cookie.Cookie> getCookies()
        Specified by:
        getCookies in interface Response
        Returns:
        the list of Cookie.
      • hasResponseStatus

        public boolean hasResponseStatus()
        Description copied from interface: Response
        Return true if the response's status has been computed by an AsyncHandler
        Specified by:
        hasResponseStatus in interface Response
        Returns:
        true if the response's status has been computed by an AsyncHandler
      • getResponseBodyAsBytes

        public byte[] getResponseBodyAsBytes()
        Description copied from interface: Response
        Return the entire response body as a byte[].
        Specified by:
        getResponseBodyAsBytes in interface Response
        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 each TransferListener is given by a TransferCompletionHandler, the one HttpResponseBodyPart.getBodyByteBuffer() wraps for a ResumableListener, and the one Response.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 implement getResponseBodyAsBytes() 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. EagerResponseBodyPart returns the array it holds; LazyResponseBodyPart copies out of its buffer on every call, so a response made of lazy parts never shares whatever this says.

        Specified by:
        getResponseBodyAsBytesView in interface Response
        Returns:
        the entire response body, possibly sharing storage with the response
      • getResponseBodyAsByteBuffer

        public ByteBuffer getResponseBodyAsByteBuffer()
        Description copied from interface: Response
        Return the entire response body as a ByteBuffer.
        Specified by:
        getResponseBodyAsByteBuffer in interface Response
        Returns:
        the entire response body as a ByteBuffer.
      • getResponseBodyAsByteBuf

        public io.netty.buffer.ByteBuf getResponseBodyAsByteBuf()
        Description copied from interface: Response
        Return the entire response body as a ByteBuf.
        Specified by:
        getResponseBodyAsByteBuf in interface Response
        Returns:
        the entire response body as a ByteBuf.
      • getResponseBody

        public String getResponseBody()
        Description copied from interface: Response
        Return the entire response body as a String.
        Specified by:
        getResponseBody in interface Response
        Returns:
        the entire response body as a String.
      • getResponseBody

        public String getResponseBody​(Charset charset)
        Description copied from interface: Response
        Return the entire response body as a String.
        Specified by:
        getResponseBody in interface Response
        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: Response
        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.
        Specified by:
        getResponseBodyAsStream in interface Response
        Returns:
        The input stream
      • toString

        public String toString()
        Description copied from interface: Response
        Subclasses SHOULD implement toString() in a way that identifies the response for logging.
        Specified by:
        toString in interface Response
        Overrides:
        toString in class Object
        Returns:
        the textual representation