add user agents

This commit is contained in:
dima_dencep 2022-09-24 00:55:51 +07:00
parent 7ae6b6dbb6
commit 4013a2d542
5 changed files with 9 additions and 1 deletions

View file

@ -3,6 +3,7 @@
import com.google.gson.JsonElement;
import pro.gravit.launcher.Launcher;
import pro.gravit.launchserver.helper.HttpHelper;
import pro.gravit.utils.helper.IOHelper;
import java.io.IOException;
import java.lang.reflect.Type;
@ -28,6 +29,7 @@ public <T> HttpRequest get(String url, String token) {
.uri(new URI(url))
.header("Content-Type", "application/json; charset=UTF-8")
.header("Accept", "application/json")
.header("User-Agent", IOHelper.USER_AGENT)
.timeout(Duration.ofMillis(10000));
if (token != null) {
requestBuilder.header("Authorization", "Bearer ".concat(token));
@ -45,6 +47,7 @@ public <T> HttpRequest post(String url, T request, String token) {
.uri(new URI(url))
.header("Content-Type", "application/json; charset=UTF-8")
.header("Accept", "application/json")
.header("User-Agent", IOHelper.USER_AGENT)
.timeout(Duration.ofMillis(10000));
if (token != null) {
requestBuilder.header("Authorization", "Bearer ".concat(token));

View file

@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.Launcher;
import pro.gravit.utils.helper.IOHelper;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -32,6 +33,7 @@ public static <T, R> R jsonRequest(T request, String url, String bearerToken, Cl
.uri(new URI(url))
.header("Content-Type", "application/json; charset=UTF-8")
.header("Accept", "application/json")
.header("User-Agent", IOHelper.USER_AGENT)
.timeout(Duration.ofMillis(10000));
if (bearerToken != null) {
request1.header("Authorization", "Bearer ".concat(bearerToken));

View file

@ -59,6 +59,7 @@ public static SSLContext makeSSLContext() throws NoSuchAlgorithmException, Certi
public void downloadFile(URL url, Path target, long size) throws IOException {
if (isClosed) throw new IOException("Download interrupted");
URLConnection connection = url.openConnection();
connection.addRequestProperty("User-Agent", IOHelper.USER_AGENT);
if (isCertificatePinning) {
HttpsURLConnection connection1 = (HttpsURLConnection) connection;
try {
@ -74,6 +75,7 @@ public void downloadFile(URL url, Path target, long size) throws IOException {
public void downloadFile(URL url, Path target) throws IOException {
URLConnection connection = url.openConnection();
connection.addRequestProperty("User-Agent", IOHelper.USER_AGENT);
if (isCertificatePinning) {
HttpsURLConnection connection1 = (HttpsURLConnection) connection;
try {

View file

@ -234,6 +234,7 @@ public static HttpURLConnection newConnectionPost(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) newConnection(url);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.addRequestProperty("User-Agent", IOHelper.USER_AGENT);
return connection;
}

View file

@ -150,7 +150,7 @@ protected HttpRequest makeHttpRequest(URI baseUri, String filePath) throws URISy
return HttpRequest.newBuilder()
.GET()
.uri(new URI(scheme, host, path + filePath, "", ""))
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36")
.header("User-Agent", IOHelper.USER_AGENT)
.build();
}