Skip to content

Commit

Permalink
Add user-agent and custom rest config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Nov 18, 2023
1 parent d30d698 commit 62ed28a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/main/java/net/dv8tion/jda/api/sharding/DefaultShardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.util.Queue;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.IntFunction;

/**
Expand Down Expand Up @@ -753,22 +754,27 @@ public okhttp3.Response execute()
{
try
{
String url = restConfigProvider.apply(0).getBaseUrl() + getRoute().getCompiledRoute();
LOG.trace("Requesting shard total with url {}", url);

Call call = httpClient.newCall(new okhttp3.Request.Builder()
.get()
.url(url)
.header("authorization", "Bot " + token)
.header("accept-encoding", "gzip")
.build()
);

RestConfig config = restConfigProvider.apply(0);
String url = config.getBaseUrl() + getRoute().getCompiledRoute();
LOG.debug("Requesting shard total with url {}", url);

okhttp3.Request.Builder builder = new okhttp3.Request.Builder()
.get()
.url(url)
.header("authorization", "Bot " + token)
.header("accept-encoding", "gzip")
.header("user-agent", config.getUserAgent());

Consumer<? super okhttp3.Request.Builder> customBuilder = config.getCustomBuilder();
if (customBuilder != null)
customBuilder.accept(builder);

Call call = httpClient.newCall(builder.build());
okhttp3.Response response = call.execute();

try
{
LOG.trace("Received response with code {}", response.code());
LOG.debug("Received response with code {}", response.code());
InputStream body = IOUtil.getBody(response);

if (response.isSuccessful())
Expand Down

0 comments on commit 62ed28a

Please sign in to comment.