Class DefaultResponse

  • All Implemented Interfaces:
    Response

    @Immutable
    @Loggable(1)
    public final class DefaultResponse
    extends Object
    implements Response
    Default implementation of Response.
    Since:
    1.0
    • Constructor Detail

      • DefaultResponse

        public DefaultResponse​(Request request,
                               int status,
                               String reason,
                               com.jcabi.immutable.Array<Map.Entry<String,​String>> headers,
                               byte[] body)
        Public ctor.
        Parameters:
        request - The request
        status - HTTP status
        reason - HTTP reason phrase
        headers - HTTP headers
        body - Body of HTTP response
    • Method Detail

      • back

        public Request back()
        Description copied from interface: Response
        Get back to the request it's related to.
        Specified by:
        back in interface Response
        Returns:
        The request we're in
      • status

        public int status()
        Description copied from interface: Response
        Get status of the response as a positive integer number.
        Specified by:
        status in interface Response
        Returns:
        The status code
      • reason

        public String reason()
        Description copied from interface: Response
        Get status line reason phrase.
        Specified by:
        reason in interface Response
        Returns:
        The status line reason phrase
      • body

        public String body()
        Description copied from interface: Response
        Get body as a string, assuming it's UTF-8 (if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).

        DISCLAIMER: The only encoding supported here is UTF-8. If the body of response contains any chars that can't be used and should be replaced with a "replacement character", a RuntimeException will be thrown. If you need to use some other encodings, use Response.binary() instead.

        Specified by:
        body in interface Response
        Returns:
        The body, as a UTF-8 string
      • binary

        public byte[] binary()
        Description copied from interface: Response
        Raw body as a an array of bytes.
        Specified by:
        binary in interface Response
        Returns:
        The body, as a UTF-8 string
      • as

        public <T extends Response> T as​(Class<T> type)
        Description copied from interface: Response
        Convert it to another type, by encapsulation.
        Specified by:
        as in interface Response
        Type Parameters:
        T - Type to use
        Parameters:
        type - Type to use
        Returns:
        New response