Class Http
java.lang.Object
net.buildtheearth.terraminusminus.util.http.Http
Handles sending and caching of HTTP requests.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOptions for controlling the behavior of outgoing HTTP requests. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final io.netty.bootstrap.Bootstrapstatic final Http.RequestOptionsprotected static final Map<net.buildtheearth.terraminusminus.util.http.Host, net.buildtheearth.terraminusminus.util.http.HostManager> protected static final intprotected static final io.netty.channel.EventLoopGroupprotected 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, with the default request options.static CompletableFuture<io.netty.buffer.ByteBuf> get(@NonNull String url, @NonNull Http.RequestOptions options) Asynchronously gets the contents of the given resource.static <T> CompletableFuture<T> getFirst(@NonNull String[] urls, @NonNull Http.RequestOptions options, @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 Http.RequestOptions options, @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_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
-
-
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 getoptions- client behavior options for this request- Returns:
- a
CompletableFuturewhich will be completed with the resource data, ornullif the resource isn't found
-
get
Asynchronously gets the contents of the given resource, with the default request options.- 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
-
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 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 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 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 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
-