Class SpeakeasyHTTPClient

java.lang.Object
com.google.genai.gaos.utils.SpeakeasyHTTPClient
All Implemented Interfaces:
HTTPClient, AutoCloseable

public class SpeakeasyHTTPClient extends Object implements HTTPClient
  • 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 Authorization headers) and should only be enabled temporarily for local debugging purposes.

      By default, Authorization headers are redacted in the logs (printed with a value of [*******]). Header suppression can be controlled with the setRedactedHeaders(Collection) method.

      Parameters:
      enabled - true to enable debug logging, false to disable it
      See Also:
    • getDebugLoggingEnabled

      public static boolean getDebugLoggingEnabled()
    • isDebugLoggingEnabled

      public boolean isDebugLoggingEnabled()
      Description copied from interface: HTTPClient
      Returns whether debug logging is enabled.
      Specified by:
      isDebugLoggingEnabled in interface HTTPClient
      Returns:
      Whether debug logging is enabled
    • enableDebugLogging

      public void enableDebugLogging(boolean enabled)
      Description copied from interface: HTTPClient
      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.
      Specified by:
      enableDebugLogging in interface HTTPClient
      Parameters:
      enabled - Whether to enable debug flag
    • setRedactedHeaders

      public static void setRedactedHeaders(Collection<String> headerNames)
      When debug logging is enabled, this method controls the suppression of header values in the logs.

      By default, Authorization headers 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

      public static void addRedactedHeader(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.

      By default, Authorization headers 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

      public static void setLogger(Consumer<? super String> logger)
    • send

      public HttpResponse<InputStream> send(HttpRequest request) throws IOException
      Description copied from interface: HTTPClient
      Sends an HTTP request and returns the response.

      Note that HttpRequest is immutable. To modify the request use HttpRequest.toBuilder() which copies the request into a builder.

      Specified by:
      send in interface HTTPClient
      Parameters:
      request - HTTP request
      Returns:
      HTTP response
      Throws:
      IOException
    • sendAsync

      public CompletableFuture<HttpResponse<InputStream>> sendAsync(HttpRequest request)
      Description copied from interface: HTTPClient
      Sends an HTTP request asynchronously and returns a response whose body is exposed as an InputStream (the same body type as the synchronous HTTPClient.send(HttpRequest)).

      The request is dispatched without blocking the calling thread. The returned CompletableFuture completes 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:
      sendAsync in interface HTTPClient
      Parameters:
      request - the HTTP request to send
      Returns:
      a CompletableFuture containing the HTTP response with an InputStream body
    • close

      public void close() throws Exception
      Description copied from interface: HTTPClient
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface HTTPClient
      Throws:
      Exception - if an owned resource cannot be released