java.lang.Object
net.buildtheearth.terraminusminus.util.http.Http

public final class Http extends Object
Handles sending and caching of HTTP requests.
  • Field Details

    • TIMEOUT

      protected static final long TIMEOUT
      See Also:
    • NETWORK_EVENT_LOOP_GROUP

      protected static final io.netty.channel.EventLoopGroup NETWORK_EVENT_LOOP_GROUP
    • DEFAULT_BOOTSTRAP

      protected static final io.netty.bootstrap.Bootstrap DEFAULT_BOOTSTRAP
    • SSL_CONTEXT

      protected static final io.netty.handler.ssl.SslContext SSL_CONTEXT
    • MANAGERS

      protected static final Map<net.buildtheearth.terraminusminus.util.http.Host,net.buildtheearth.terraminusminus.util.http.HostManager> MANAGERS
    • MAX_CONTENT_LENGTH

      protected static final int MAX_CONTENT_LENGTH
      See Also:
    • URL_FORMATTING_MATCHER_CACHE

      protected static final net.daporkchop.lib.common.reference.cache.Cached<Matcher> URL_FORMATTING_MATCHER_CACHE
    • DEFAULT_REQUEST_OPTIONS

      public static final Http.RequestOptions DEFAULT_REQUEST_OPTIONS
  • Method Details

    • get

      public static CompletableFuture<io.netty.buffer.ByteBuf> get(@NonNull @NonNull String url, @NonNull @NonNull Http.RequestOptions options)
      Asynchronously gets the contents of the given resource.
      Parameters:
      url - the url of the resource to get
      options - client behavior options for this request
      Returns:
      a CompletableFuture which will be completed with the resource data, or null if the resource isn't found
    • get

      public static CompletableFuture<io.netty.buffer.ByteBuf> get(@NonNull @NonNull String url)
      Asynchronously gets the contents of the given resource, with the default request options.
      Parameters:
      url - the url of the resource to get
      Returns:
      a CompletableFuture which will be completed with the resource data, or null if the resource isn't found
    • setMaximumConcurrentRequestsTo

      public static void setMaximumConcurrentRequestsTo(@NonNull @NonNull String host, int maxConcurrentRequests)
      Sets the maximum number of concurrent requests to the given remote host.
      Parameters:
      host - the host. May be any valid URL, however only the protocol and authority components will be considered
      maxConcurrentRequests - the new maximum number of concurrent requests to the host
    • getFirst

      public static <T> CompletableFuture<T> getFirst(@NonNull @NonNull String[] urls, @NonNull @NonNull Http.RequestOptions options, @NonNull @NonNull net.daporkchop.lib.common.function.throwing.EFunction<io.netty.buffer.ByteBuf,T> parseFunction)
      Attempts to GET an array of URLs in order, returning the parsed response body of the first successful one.
      Parameters:
      urls - the URLs
      parseFunction - a function to use to parse the response body
      Returns:
      the parsed response body
    • getSingle

      public static <T> CompletableFuture<T> getSingle(@NonNull @NonNull String url, @NonNull @NonNull Http.RequestOptions options, @NonNull @NonNull net.daporkchop.lib.common.function.throwing.EFunction<io.netty.buffer.ByteBuf,T> parseFunction)
      Attempts to GET a single URL.
      Parameters:
      url - the URL
      parseFunction - a function to use to parse the response body
      Returns:
      the parsed response body
    • formatUrl

      public static String formatUrl(@NonNull @NonNull Map<String,String> properties, @NonNull @NonNull String url)
    • configChanged

      public static void configChanged()
    • copyResultTo

      protected static <T> void copyResultTo(@NonNull @NonNull CompletableFuture<T> src, @NonNull @NonNull CompletableFuture<T> dst)
    • userAgent

      public static String userAgent()
    • userAgent

      public static void userAgent(String userAgent)