java.lang.Object
org.miaixz.bus.http.Httpv
A high-level HTTP client that provides a fluent and expressive API for making HTTP requests. It is built on top of
Httpd and adds features like pre-processing, task management, and simplified request creation.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder for creating and configuringHttpvinstances.static interfaceAn interface for configuring the underlyingHttpd.Builder.static classA preprocessor that ensures serial execution of other preprocessors.classRepresents a task that is associated with a tag for easy cancellation. -
Constructor Summary
ConstructorsConstructorDescriptionHttpv()Default constructor.Httpv(Httpv.Builder builder) Constructs anHttpvinstance with the configuration from the given builder. -
Method Summary
Modifier and TypeMethodDescriptionaddTagTask(String tag, Cancelable canceler, CoverHttp<?> task) Adds a new tagged task to the list of ongoing tasks.Starts an asynchronous HTTP request.baseUrl()Gets the base URL.bodyType()Gets the default body type.static Httpv.Builderbuilder()Creates a new builder for constructing anHttpvinstance.intCancels all ongoing requests that are associated with the given tag.voidCancels all ongoing requests and clears all tagged tasks.charset()Gets the default charset.org.miaixz.bus.core.lang.MediaTypecontentType(String type) Gets theMediaTypefor a given type string based on the configured media types.executor()Gets the executor for handling asynchronous tasks.intGets the current number of tagged tasks.httpd()Gets the underlyingHttpdclient.Gets the map of media types.Creates a new builder initialized with the configuration of thisHttpvinstance.voidpreprocess(CoverHttp<? extends CoverHttp<?>> coverHttp, Runnable request, boolean skipPreproc, boolean skipSerialPreproc) Executes the pre-processing chain for a given request.Gets the array of preprocessors.intCalculates the timeout for pre-processing tasks in milliseconds.intGets the pre-processing timeout multiplier.voidremoveTagTask(CoverHttp<?> task) Removes a tagged task from the list of ongoing tasks.Creates a new call for the given request using the underlyingHttpdclient.Starts a synchronous HTTP request.tagTasks()Gets the list of tagged tasks.Starts a WebSocket connection.webSocket(Request request, WebSocketListener listener) Creates a new WebSocket connection using the underlyingHttpdclient.
-
Constructor Details
-
Httpv
public Httpv()Default constructor. -
Httpv
Constructs anHttpvinstance with the configuration from the given builder.- Parameters:
builder- The builder to configure this instance.
-
-
Method Details
-
builder
Creates a new builder for constructing anHttpvinstance.- Returns:
- a new
Httpv.Builder.
-
async
Starts an asynchronous HTTP request.- Parameters:
url- The URL for the request. Can be a relative or absolute path.- Returns:
- An
CoverHttp.Asyncinstance for building and executing the request.
-
sync
Starts a synchronous HTTP request.- Parameters:
url- The URL for the request. Can be a relative or absolute path.- Returns:
- A
CoverHttp.Syncinstance for building and executing the request.
-
webSocket
Starts a WebSocket connection.- Parameters:
url- The URL for the WebSocket. Can be a relative or absolute path.- Returns:
- A
CoverCall.Clientinstance for establishing the WebSocket connection.
-
cancel
Cancels all ongoing requests that are associated with the given tag.- Parameters:
tag- The tag to identify which requests to cancel.- Returns:
- The number of requests that were successfully canceled.
-
cancelAll
public void cancelAll()Cancels all ongoing requests and clears all tagged tasks. -
request
Creates a new call for the given request using the underlyingHttpdclient.- Parameters:
request- The request to execute.- Returns:
- A new
NewCall.
-
webSocket
Creates a new WebSocket connection using the underlyingHttpdclient.- Parameters:
request- The WebSocket request.listener- The listener for WebSocket events.- Returns:
- A new
WebSocket.
-
httpd
Gets the underlyingHttpdclient.- Returns:
- The
Httpdinstance.
-
preprocTimeoutMillis
public int preprocTimeoutMillis()Calculates the timeout for pre-processing tasks in milliseconds.- Returns:
- The pre-processing timeout in milliseconds.
-
getTagTaskCount
public int getTagTaskCount()Gets the current number of tagged tasks.- Returns:
- The number of tagged tasks.
-
addTagTask
Adds a new tagged task to the list of ongoing tasks.- Parameters:
tag- The tag for the task.canceler- The object that can cancel the task.task- The task itself.- Returns:
- The newly created
Httpv.TagTask.
-
removeTagTask
Removes a tagged task from the list of ongoing tasks.- Parameters:
task- The task to remove.
-
contentType
Gets theMediaTypefor a given type string based on the configured media types.- Parameters:
type- The type string (e.g., "png", "json").- Returns:
- The corresponding
MediaType, orapplication/octet-streamif not found.
-
executor
Gets the executor for handling asynchronous tasks.- Returns:
- The
CoverTasks.Executor.
-
preprocess
public void preprocess(CoverHttp<? extends CoverHttp<?>> coverHttp, Runnable request, boolean skipPreproc, boolean skipSerialPreproc) Executes the pre-processing chain for a given request.- Parameters:
coverHttp- The HTTP task being processed.request- The final request action to run after pre-processing.skipPreproc- Whether to skip all pre-processors.skipSerialPreproc- Whether to skip serial pre-processors.
-
newBuilder
Creates a new builder initialized with the configuration of thisHttpvinstance.- Returns:
- A new
Httpv.Builder.
-
baseUrl
Gets the base URL.- Returns:
- The base URL.
-
mediaTypes
Gets the map of media types.- Returns:
- The map of media types.
-
preprocessors
Gets the array of preprocessors.- Returns:
- The array of preprocessors.
-
tagTasks
Gets the list of tagged tasks.- Returns:
- The list of tagged tasks.
-
preprocTimeoutTimes
public int preprocTimeoutTimes()Gets the pre-processing timeout multiplier.- Returns:
- The pre-processing timeout multiplier.
-
charset
Gets the default charset.- Returns:
- The default charset.
-
bodyType
Gets the default body type.- Returns:
- The default body type.
-