public final class ClientRequest extends Object
HttpClient.| Constructor and Description |
|---|
ClientRequest(Method method,
String requestTarget,
Headers headers)
Constructs a
ClientRequest representing a HTTP request without a body. |
ClientRequest(Method method,
String requestTarget,
Headers headers,
byte[] body)
Constructs a
ClientRequest representing a HTTP request with a body. |
| Modifier and Type | Method and Description |
|---|---|
static Headers |
createHeaders()
A helper method to create a
Headers instance. |
boolean |
equals(Object o)
Two
ClientRequest instances are considered equal if their serialized representations are equal. |
byte[] |
getBody() |
Headers |
getHeaders() |
Method |
getMethod() |
String |
getRequestTarget() |
int |
hashCode()
Similar to
equals(Object), the hash code is computed based on the serialized representation |
String |
toString()
Returns a String representation of this request.
|
public ClientRequest(Method method, String requestTarget, Headers headers)
ClientRequest representing a HTTP request without a body.method - the HTTP method for the requestrequestTarget - the request target to include in the request line. Typically, this of the form
/path?queryheaders - the Headers representing the header fields of the request. An instance of Headers
can be created using createHeaders() or a HeadersFactory.IllegalArgumentException - when the specified data for the request is invalid:
URLEncoder can be used to perform this
encoding.Headers contain a Content-Length or Transfer-Encoding header field, these
header fields will be set appropriately by PingAccess.Headers contain a Host header field. This header field will be set based on
administrator-defined configuration.Headers instance contain characters that are not
representable in the ISO-8859-1 charset.Headers instance contains a carriage return or
line feed.public ClientRequest(Method method, String requestTarget, Headers headers, byte[] body)
ClientRequest representing a HTTP request with a body.method - the HTTP method for the requestrequestTarget - the request target (a.k.a. the request URI) to include in the request line.
Typically, this is of the form /path?query.headers - the Headers representing the header fields of the request. An instance of Headers
can be created using createHeaders() or a HeadersFactory.body - the bytes for the request body. For the sake of performance, the specified byte array is NOT
copied. Users of this class must ensure the specified array is not changed after constructing
an instance.IllegalArgumentException - when the specified data for the request is invalid:
URLEncoder can be used to perform this
encoding.Headers contain a Content-Length or Transfer-Encoding header field, these
header fields will be set appropriately by PingAccess based on the length of body.Headers contain a Host header field. This header field will be set based on
administrator-defined configuration.Headers instance contain characters that are not
representable in the ISO-8859-1 charset.Headers instance contains a carriage return or
line feed.public static Headers createHeaders()
Headers instance.Headers instancepublic Method getMethod()
public String getRequestTarget()
public Headers getHeaders()
Headers representing the header fields for this requestpublic byte[] getBody()
public String toString()
The representation only includes the length of the body to avoid inadvertently logging sensitive data that is often present in request body. Further, the Authorization and Cookie header fields are included with content redacted for the same reason.
Example output:ClientRequest[method=GET,requestTarget="/path?query",headers=[authorization: "<redacted>", x-custom:"value"],body=0]
public boolean equals(Object o)
ClientRequest instances are considered equal if their serialized representations are equal.
That is, the following requests are not considered equal, despite being semantically equivalent:
GET / HTTP/1.1[\r][\n] Host: www.example.com[\r][\n] X-Custom: one Accept: application/json X-Custom: two [\r][\n]
GET / HTTP/1.1[\r][\n] Host: www.example.com[\r][\n] X-Custom: one,two[\r][\n] Accept: application/json[\r][\n] [\r][\n]
PingAccess does not provide a semantic equivalence equals implementation because doing so requires the ability to canonicalize the payload body, which is not feasible. Further, while PingAccess might consider certain requests semantically equivalent, variations in HTTP server specification compliance might result in a server classifying those same requests as semantically different.
As a result, PingAccess uses a more conservative approach that ensures equal ClientRequest
instances will result in the same server handling.
equals in class Objecto - the other ClientRequestObject equals this ClientRequestpublic int hashCode()
equals(Object), the hash code is computed based on the serialized representationhashCode in class ObjectClientRequestCopyright 2023 Ping Identity Corp. All rights reserved.