- 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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn interface for consuming the HTTP response body in various formats.static classThe concrete implementation ofCoverResult.static enumRepresents the final state of an HTTP task. -
Method Summary
Modifier and TypeMethodDescriptionclose()Closes the underlying response.getBody()Retrieves the response body handler.longGets the response body length as specified by the 'Content-Length' header.getError()Retrieves the exception that occurred during execution, if any.Retrieves the first header value for a given name.Retrieves the headers from the HTTP response.getHeaders(String name) Retrieves all header values for a given name.getState()Retrieves the final state of the HTTP execution.intRetrieves the HTTP status code from the response.booleanChecks if the response was successful (i.e., the status code is in the range [200..299]).static CoverResultCreates aCoverResultfrom a rawResponse.static CoverResultof(Response response, CoverTasks.Executor executor) Creates a fully functionalCoverResultfrom a rawResponseand a task executor.
-
Method Details
-
of
Creates aCoverResultfrom a rawResponse. 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 rawResponsefrom the HTTP client.- Returns:
- A new
CoverResultinstance.
-
of
Creates a fully functionalCoverResultfrom a rawResponseand a task executor.- Parameters:
response- The rawResponsefrom the HTTP client.executor- The task executor, typically obtained fromHttpv.executor().- Returns:
- A new
CoverResultinstance.
-
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:
trueif the response was successful,falseotherwise.
-
getHeaders
Headers getHeaders()Retrieves the headers from the HTTP response.- Returns:
- The response
Headers.
-
getHeaders
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
Retrieves the first header value for a given name.- Parameters:
name- The case-insensitive header name.- Returns:
- The header value, or
nullif 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, butCoverResult.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.Bodyobject for consuming the response content.
-
getError
IOException getError()Retrieves the exception that occurred during execution, if any.- Returns:
- The
IOExceptionthat caused the failure, ornullif 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
CoverResultinstance.
-