Module bus.http

Interface CoverResult

All Known Implementing Classes:
CoverResult.Real

public interface CoverResult
Represents the result of an HTTP execution. This interface provides access to the response status, headers, body, and any errors that may have occurred during the request.
Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • of

      static CoverResult of(Response response)
      Creates a CoverResult from a raw Response. Note: Results created this way cannot have progress callbacks set or perform download operations, as they lack a task executor. This is suitable for simple, synchronous use cases.
      Parameters:
      response - The raw Response from the HTTP client.
      Returns:
      A new CoverResult instance.
    • of

      static CoverResult of(Response response, CoverTasks.Executor executor)
      Creates a fully functional CoverResult from a raw Response and a task executor.
      Parameters:
      response - The raw Response from the HTTP client.
      executor - The task executor, typically obtained from Httpv.executor().
      Returns:
      A new CoverResult instance.
    • getState

      CoverResult.State getState()
      Retrieves the final state of the HTTP execution.
      Returns:
      The execution CoverResult.State.
    • getStatus

      int getStatus()
      Retrieves the HTTP status code from the response.
      Returns:
      The HTTP status code (e.g., 200, 404). Returns 0 if no response was received.
    • isSuccessful

      boolean isSuccessful()
      Checks if the response was successful (i.e., the status code is in the range [200..299]).
      Returns:
      true if the response was successful, false otherwise.
    • getHeaders

      Headers getHeaders()
      Retrieves the headers from the HTTP response.
      Returns:
      The response Headers.
    • getHeaders

      List<String> getHeaders(String name)
      Retrieves all header values for a given name.
      Parameters:
      name - The case-insensitive header name.
      Returns:
      A list of header values, or an empty list if the header is not present.
    • getHeader

      String getHeader(String name)
      Retrieves the first header value for a given name.
      Parameters:
      name - The case-insensitive header name.
      Returns:
      The header value, or null if the header is not present.
    • getContentLength

      long getContentLength()
      Gets the response body length as specified by the 'Content-Length' header. Note: For HEAD requests, this method may return a non-zero value, but CoverResult.Body.getLength() will return 0 because there is no actual body content.
      Returns:
      The content length in bytes, or 0 if not specified.
    • getBody

      CoverResult.Body getBody()
      Retrieves the response body handler.
      Returns:
      The CoverResult.Body object for consuming the response content.
    • getError

      IOException getError()
      Retrieves the exception that occurred during execution, if any.
      Returns:
      The IOException that caused the failure, or null if the request was successful.
    • close

      CoverResult close()
      Closes the underlying response. This should be called to release resources, especially if the response body is not fully consumed.
      Returns:
      This CoverResult instance.