Class Http
java.lang.Object
net.buildtheearth.terraminusminus.util.http.Http
Handles sending and caching of HTTP requests.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final io.netty.bootstrap.Bootstrapprotected static final Map<net.buildtheearth.terraminusminus.util.http.Host, net.buildtheearth.terraminusminus.util.http.HostManager> protected static final intprotected static final io.netty.channel.EventLoopprotected static final io.netty.handler.ssl.SslContextprotected static final longprotected static final net.daporkchop.lib.common.reference.cache.Cached<Matcher> -
Method Summary
Modifier and TypeMethodDescriptionstatic voidprotected static <T> voidcopyResultTo(@NonNull CompletableFuture<T> src, @NonNull CompletableFuture<T> dst) static Stringstatic CompletableFuture<io.netty.buffer.ByteBuf> Asynchronously gets the contents of the given resource.static voidget(@NonNull String _url, @NonNull CompletableFuture<io.netty.buffer.ByteBuf> future) static <T> CompletableFuture<T> getFirst(@NonNull String[] urls, @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.static <T> CompletableFuture<T> getSingle(@NonNull String url, @NonNull net.daporkchop.lib.common.function.throwing.EFunction<io.netty.buffer.ByteBuf, T> parseFunction) Attempts to GET a single URL.static voidsetMaximumConcurrentRequestsTo(@NonNull String host, int maxConcurrentRequests) Sets the maximum number of concurrent requests to the given remote host.static Stringstatic void
-
Field Details
-
TIMEOUT
protected static final long TIMEOUT- See Also:
-
NETWORK_EVENT_LOOP
protected static final io.netty.channel.EventLoop NETWORK_EVENT_LOOP -
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
-
-
Method Details
-
get
Asynchronously gets the contents of the given resource.- Parameters:
url- the url of the resource to get- Returns:
- a
CompletableFuturewhich will be completed with the resource data, ornullif the resource isn't found
-
get
public static void get(@NonNull @NonNull String _url, @NonNull @NonNull CompletableFuture<io.netty.buffer.ByteBuf> future) -
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 consideredmaxConcurrentRequests- the new maximum number of concurrent requests to the host
-
getFirst
public static <T> CompletableFuture<T> getFirst(@NonNull @NonNull String[] urls, @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 URLsparseFunction- 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 net.daporkchop.lib.common.function.throwing.EFunction<io.netty.buffer.ByteBuf, T> parseFunction) Attempts to GET a single URL.- Parameters:
url- the URLparseFunction- a function to use to parse the response body- Returns:
- the parsed response body
-
formatUrl
-
configChanged
public static void configChanged() -
copyResultTo
protected static <T> void copyResultTo(@NonNull @NonNull CompletableFuture<T> src, @NonNull @NonNull CompletableFuture<T> dst) -
userAgent
-
userAgent
-