Package com.google.genai.gaos.utils
Interface HTTPClient
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
RecordingClient,SpeakeasyHTTPClient
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Releases resources owned by this client.default voidenableDebugLogging(boolean enabled) Controls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses.default booleanReturns 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 synchronoussend(HttpRequest)).
-
Method Details
-
close
Releases 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- Throws:
Exception- if an owned resource cannot be released
-
send
Sends an HTTP request and returns the response.Note that
HttpRequestis immutable. To modify the request useHttpRequest.toBuilder()which copies the request into a builder.- Parameters:
request- HTTP request- Returns:
- HTTP response
- Throws:
IOException
-
sendAsync
Sends an HTTP request asynchronously and returns a response whose body is exposed as anInputStream(the same body type as the synchronoussend(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.- Parameters:
request- the HTTP request to send- Returns:
- a
CompletableFuturecontaining the HTTP response with anInputStreambody
-
enableDebugLogging
default void enableDebugLogging(boolean enabled) Controls 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.- Parameters:
enabled- Whether to enable debug flag
-
isDebugLoggingEnabled
default boolean isDebugLoggingEnabled()Returns whether debug logging is enabled.- Returns:
- Whether debug logging is enabled
-