Interface HttpResponse

  • All Superinterfaces:
    AutoCloseable

    public interface HttpResponse
    extends AutoCloseable
    Represents an HTTP response message.
    Since:
    4.0.0
    Author:
    Dmytro Nosan
    • Method Detail

      • getUri

        URI getUri()
        Returns the URI of the HTTP request that resulted in this response.
        Returns:
        the URI of the associated HTTP request
      • getStatus

        int getStatus()
        Returns the HTTP status code of the response.
        Returns:
        the HTTP status code
      • getHeaders

        HttpHeaders getHeaders()
        Returns the headers associated with this HTTP response.
        Returns:
        a HttpHeaders object representing the response headers
      • getInputStream

        InputStream getInputStream()
                            throws IOException
        Returns the body of the HTTP response as an InputStream.

        The response body is available for reading as raw byte content using this stream. It is important to ensure this stream is fully read or closed to properly release resources.

        Returns:
        an InputStream containing the response body
        Throws:
        IOException - if an I/O error occurs while retrieving the body
      • close

        void close()
            throws IOException
        Closes the response and releases any underlying resources.

        It is recommended to use a try-with-resources statement when working with HttpResponse to automatically handle resource cleanup:

        
         try (HttpResponse response = client.send(request)) {
             InputStream body = response.getInputStream();
             // Process the response body
         }
         
        Specified by:
        close in interface AutoCloseable
        Throws:
        IOException - if an I/O error occurs while closing the response