Class SpeakeasyHTTPClient

  • All Implemented Interfaces:
    HTTPClient

    public class SpeakeasyHTTPClient
    extends java.lang.Object
    implements HTTPClient
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      static boolean getDebugLoggingEnabled()  
      boolean isDebugLoggingEnabled()
      Returns whether debug logging is enabled.
      java.net.http.HttpResponse<java.io.InputStream> send​(java.net.http.HttpRequest request)
      Sends an HTTP request and returns the response.
      java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> sendAsync​(java.net.http.HttpRequest request)
      Sends an HTTP request asynchronously and returns a response whose body is exposed as a Blob.
      static void setDebugLogging​(boolean enabled)
      Experimental, may be changed anytime.
      static void setLogger​(java.util.function.Consumer<? super java.lang.String> logger)  
      static void setRedactedHeaders​(java.util.Collection<java.lang.String> headerNames)
      Experimental, may be changed anytime.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SpeakeasyHTTPClient

        public SpeakeasyHTTPClient()
    • Method Detail

      • setDebugLogging

        public static void setDebugLogging​(boolean enabled)
        Experimental, may be changed anytime. Sets debug logging on or off for requests and responses including bodies for JSON content. WARNING: this setting may expose sensitive information in logs (like 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 is controlled with the setRedactedHeaders(Collection) method.
        Parameters:
        enabled - true to enable debug logging, false to disable it
      • 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​(java.util.Collection<java.lang.String> headerNames)
        Experimental, may be changed anytime. 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 [*******]). Header suppression is controlled with the setRedactedHeaders(Collection) method.
        Parameters:
        headerNames - the names (case-insensitive) of the headers whose values will be redacted in the logs
      • setLogger

        public static void setLogger​(java.util.function.Consumer<? super java.lang.String> logger)
      • send

        public java.net.http.HttpResponse<java.io.InputStream> send​(java.net.http.HttpRequest request)
                                                             throws java.io.IOException,
                                                                    java.lang.InterruptedException,
                                                                    java.net.URISyntaxException
        Description copied from interface: HTTPClient
        Sends an HTTP request and returns the response.

        Note that HttpRequest is immutable. To modify the request you can use HttpRequest#newBuilder(HttpRequest, BiPredicate<String, String>) with JDK 16 and later (which will copy the request for modification in a builder). If that method is not available then use Helpers.copy(java.net.http.HttpRequest) (which also returns a builder).

        Specified by:
        send in interface HTTPClient
        Parameters:
        request - HTTP request
        Returns:
        HTTP response
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.net.URISyntaxException
      • sendAsync

        public java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> sendAsync​(java.net.http.HttpRequest request)
        Description copied from interface: HTTPClient
        Sends an HTTP request asynchronously and returns a response whose body is exposed as a Blob.

        This method uses the HttpResponse.BodyHandlers.ofPublisher() to obtain the response body as a Flow.Publisher<List<ByteBuffer>>, which is then wrapped in a Blob for non-blocking, reactive consumption of the response data.

        The returned CompletableFuture completes when the response is received, 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 a Blob body