java.lang.Object
org.miaixz.bus.http.Response.Builder
- Enclosing class:
Response
A builder for creating and modifying
Response instances.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a header, preserving any existing headers with the same name.body(ResponseBody body) Sets the response body.build()Builds a newResponseinstance.cacheResponse(Response cacheResponse) Sets the cache response.code(int code) Sets the HTTP status code.Sets the TLS handshake information.Sets a header, replacing any existing headers with the same name.Sets all headers, replacing any existing headers.Sets the HTTP status message.networkResponse(Response networkResponse) Sets the network response.priorResponse(Response priorResponse) Sets the prior response.protocol(org.miaixz.bus.core.net.Protocol protocol) Sets the protocol used.receivedResponseAtMillis(long receivedResponseAtMillis) Sets the timestamp when the response headers were received.removeHeader(String name) Removes all headers with the given name.Sets the request that initiated this response.sentRequestAtMillis(long sentRequestAtMillis) Sets the timestamp when the request was sent.
-
Constructor Details
-
Builder
public Builder()Default constructor that initializes an empty builder.
-
-
Method Details
-
request
Sets the request that initiated this response.- Parameters:
request- TheRequestobject.- Returns:
- this builder instance.
-
protocol
Sets the protocol used.- Parameters:
protocol- The protocol (e.g., HTTP/1.1, HTTP/2).- Returns:
- this builder instance.
-
code
Sets the HTTP status code.- Parameters:
code- The status code.- Returns:
- this builder instance.
-
message
Sets the HTTP status message.- Parameters:
message- The status message.- Returns:
- this builder instance.
-
handshake
Sets the TLS handshake information.- Parameters:
handshake- TheHandshakeobject, which may be null.- Returns:
- this builder instance.
-
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.- 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.
-
body
Sets the response body.- Parameters:
body- TheResponseBodyobject, which may be null.- Returns:
- this builder instance.
-
networkResponse
Sets the network response.- Parameters:
networkResponse- The networkResponseobject, which may be null.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- ifnetworkResponsehas invalid properties.
-
cacheResponse
Sets the cache response.- Parameters:
cacheResponse- The cachedResponseobject, which may be null.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- ifcacheResponsehas invalid properties.
-
priorResponse
Sets the prior response.- Parameters:
priorResponse- The priorResponseobject, which may be null.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- ifpriorResponsecontains a body.
-
sentRequestAtMillis
Sets the timestamp when the request was sent.- Parameters:
sentRequestAtMillis- The timestamp in milliseconds.- Returns:
- this builder instance.
-
receivedResponseAtMillis
Sets the timestamp when the response headers were received.- Parameters:
receivedResponseAtMillis- The timestamp in milliseconds.- Returns:
- this builder instance.
-
build
Builds a newResponseinstance.- Returns:
- A new
Responseobject. - Throws:
IllegalStateException- if request, protocol, or message is null, or if code is less than 0.
-