java.lang.Object
org.miaixz.bus.http.Request.Builder
- Enclosing class:
Request
A builder for creating and modifying
Request instances.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a header, preserving any existing headers with the same name.build()Builds a newRequestinstance.cacheControl(CacheControl cacheControl) Sets the cache control header.delete()Sets this request to be a DELETE request with no request body.delete(RequestBody body) Sets this request to be a DELETE request with a request body.get()Sets this request to be a GET request.head()Sets this request to be a HEAD request.Sets a header, replacing any existing headers with the same name.Sets all headers, replacing any existing headers.method(String method, RequestBody body) Sets the HTTP method and request body.patch(RequestBody body) Sets this request to be a PATCH request.post(RequestBody body) Sets this request to be a POST request.put(RequestBody body) Sets this request to be a PUT request.removeHeader(String name) Removes all headers with the given name.<T> Request.BuilderAttaches a tag to this request using the specified type as the key.Attaches a tag to this request usingObject.classas the key.Sets the URL for this request from a string.Sets the URL for this request from aURLobject.Sets the URL for this request.
-
Constructor Details
-
Builder
public Builder()Default constructor that initializes a GET request.
-
-
Method Details
-
url
Sets the URL for this request.- Parameters:
url- TheUnoUrlobject.- Returns:
- this builder instance.
- Throws:
NullPointerException- if url is null.
-
url
Sets the URL for this request from a string.This converts WebSocket URLs (ws: or wss:) to HTTP URLs (http: or https:).
- Parameters:
url- The URL string.- Returns:
- this builder instance.
- Throws:
NullPointerException- if url is null.IllegalArgumentException- if the URL is invalid.
-
url
Sets the URL for this request from aURLobject.- Parameters:
url- TheURLobject.- Returns:
- this builder instance.
- Throws:
NullPointerException- if url is null.IllegalArgumentException- if the URL scheme is not http or https.
-
header
Sets a header, replacing any existing headers with the same name.- Parameters:
name- The header name.value- The header value.- Returns:
- this builder instance.
-
addHeader
Adds a header, preserving any existing headers with the same name.For certain headers (like Content-Length, Content-Encoding), the HTTP client may replace the value based on the request body.
- Parameters:
name- The header name.value- The header value.- Returns:
- this builder instance.
-
removeHeader
Removes all headers with the given name.- Parameters:
name- The header name.- Returns:
- this builder instance.
-
headers
Sets all headers, replacing any existing headers.- Parameters:
headers- TheHeadersobject.- Returns:
- this builder instance.
-
cacheControl
Sets the cache control header.This replaces any existing Cache-Control header. If
cacheControlhas no directives, the Cache-Control header will be removed.- Parameters:
cacheControl- TheCacheControlobject.- Returns:
- this builder instance.
-
get
Sets this request to be a GET request.- Returns:
- this builder instance.
-
head
Sets this request to be a HEAD request.- Returns:
- this builder instance.
-
post
Sets this request to be a POST request.- Parameters:
body- The request body.- Returns:
- this builder instance.
-
delete
Sets this request to be a DELETE request with a request body.- Parameters:
body- The request body.- Returns:
- this builder instance.
-
delete
Sets this request to be a DELETE request with no request body.- Returns:
- this builder instance.
-
put
Sets this request to be a PUT request.- Parameters:
body- The request body.- Returns:
- this builder instance.
-
patch
Sets this request to be a PATCH request.- Parameters:
body- The request body.- Returns:
- this builder instance.
-
method
Sets the HTTP method and request body.- Parameters:
method- The HTTP method.body- The request body, which may be null.- Returns:
- this builder instance.
- Throws:
NullPointerException- if method is null.IllegalArgumentException- if method is empty or if the body is not compatible with the method.
-
tag
Attaches a tag to this request usingObject.classas the key.- Parameters:
tag- The tag object.- Returns:
- this builder instance.
-
tag
Attaches a tag to this request using the specified type as the key.Tags can be used to attach metadata for debugging, timing, or other purposes, and can be read in interceptors, event listeners, or callbacks. Use null to remove an existing tag of the specified type.
- Type Parameters:
T- The type of the tag value.- Parameters:
type- The type of the tag.tag- The tag value, which may be null.- Returns:
- this builder instance.
- Throws:
NullPointerException- if type is null.
-
build
Builds a newRequestinstance.- Returns:
- A new
Requestobject. - Throws:
IllegalStateException- if the URL is not set.
-