Class SpeakeasyHTTPClient
- All Implemented Interfaces:
HTTPClient,AutoCloseable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddRedactedHeader(String headerName) When debug logging is enabled, this method adds a single header to the list of headers whose values will be redacted in the logs.voidclose()Releases resources owned by this client.voidenableDebugLogging(boolean enabled) Controls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses.static booleanbooleanReturns whether debug logging is enabled.send(HttpRequest request) Sends an HTTP request and returns the response.sendAsync(HttpRequest request) Sends an HTTP request asynchronously and returns a response whose body is exposed as anInputStream(the same body type as the synchronousHTTPClient.send(HttpRequest)).static voidsetDebugLogging(boolean enabled) Sets debug logging on or off for requests and responses including bodies for JSON content.static voidstatic voidsetRedactedHeaders(Collection<String> headerNames) When debug logging is enabled, this method controls the suppression of header values in the logs.
-
Constructor Details
-
SpeakeasyHTTPClient
public SpeakeasyHTTPClient()
-
-
Method Details
-
setDebugLogging
public static void setDebugLogging(boolean enabled) Sets debug logging on or off for requests and responses including bodies for JSON content.WARNING: This setting may expose sensitive information in logs (such as
Authorizationheaders) and should only be enabled temporarily for local debugging purposes.By default,
Authorizationheaders are redacted in the logs (printed with a value of[*******]). Header suppression can be controlled with thesetRedactedHeaders(Collection)method.- Parameters:
enabled-trueto enable debug logging,falseto disable it- See Also:
-
getDebugLoggingEnabled
public static boolean getDebugLoggingEnabled() -
isDebugLoggingEnabled
public boolean isDebugLoggingEnabled()Description copied from interface:HTTPClientReturns whether debug logging is enabled.- Specified by:
isDebugLoggingEnabledin interfaceHTTPClient- Returns:
- Whether debug logging is enabled
-
enableDebugLogging
public void enableDebugLogging(boolean enabled) Description copied from interface:HTTPClientControls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses. This is currently implemented in SpeakeasyHTTPClient but custom client implementations are free to use this method similarly if they wish.- Specified by:
enableDebugLoggingin interfaceHTTPClient- Parameters:
enabled- Whether to enable debug flag
-
setRedactedHeaders
When debug logging is enabled, this method controls the suppression of header values in the logs.By default,
Authorizationheaders are redacted in the logs (printed with a value of[*******]).- Parameters:
headerNames- the names (case-insensitive) of the headers whose values will be redacted in the logs- See Also:
-
addRedactedHeader
When debug logging is enabled, this method adds a single header to the list of headers whose values will be redacted in the logs.By default,
Authorizationheaders are redacted in the logs (printed with a value of[*******]).- Parameters:
headerName- the name (case-insensitive) of the header whose value will be redacted in the logs- See Also:
-
setLogger
-
send
Description copied from interface:HTTPClientSends an HTTP request and returns the response.Note that
HttpRequestis immutable. To modify the request useHttpRequest.toBuilder()which copies the request into a builder.- Specified by:
sendin interfaceHTTPClient- Parameters:
request- HTTP request- Returns:
- HTTP response
- Throws:
IOException
-
sendAsync
Description copied from interface:HTTPClientSends an HTTP request asynchronously and returns a response whose body is exposed as anInputStream(the same body type as the synchronousHTTPClient.send(HttpRequest)).The request is dispatched without blocking the calling thread. The returned
CompletableFuturecompletes when the response headers are received — the body is not read at that point — or completes exceptionally if an error occurs during the request or response processing.- Specified by:
sendAsyncin interfaceHTTPClient- Parameters:
request- the HTTP request to send- Returns:
- a
CompletableFuturecontaining the HTTP response with anInputStreambody
-
close
Description copied from interface:HTTPClientReleases resources owned by this client.The default is a no-op so custom implementations that borrow an externally owned client are not forced to tear down resources they do not own. Implementations that own resources should override this method.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceHTTPClient- Throws:
Exception- if an owned resource cannot be released
-