3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-01 23:50:11 +02:00

Add a User-Agent to the rest of the web requests (#932)

Dieser Commit ist enthalten in:
rtm516 2020-07-11 18:22:02 +01:00 committet von GitHub
Ursprung 4daa568311
Commit 5e5e3b0d28
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 10 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -36,6 +36,7 @@ import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -379,7 +380,11 @@ public class SkinProvider {
private static BufferedImage downloadImage(String imageUrl, CapeProvider provider) throws IOException { private static BufferedImage downloadImage(String imageUrl, CapeProvider provider) throws IOException {
if (provider == CapeProvider.FIVEZIG) if (provider == CapeProvider.FIVEZIG)
return readFiveZigCape(imageUrl); return readFiveZigCape(imageUrl);
BufferedImage image = ImageIO.read(new URL(imageUrl));
HttpURLConnection con = (HttpURLConnection) new URL(imageUrl).openConnection();
con.setRequestProperty("User-Agent", "Geyser-" + GeyserConnector.getInstance().getPlatformType().toString() + "/" + GeyserConnector.VERSION);
BufferedImage image = ImageIO.read(con.getInputStream());
if (image == null) throw new NullPointerException(); if (image == null) throw new NullPointerException();
return image; return image;
} }

Datei anzeigen

@ -77,7 +77,9 @@ public class WebUtils {
*/ */
public static void downloadFile(String reqURL, String fileLocation) { public static void downloadFile(String reqURL, String fileLocation) {
try { try {
InputStream in = new URL(reqURL).openStream(); HttpURLConnection con = (HttpURLConnection) new URL(reqURL).openConnection();
con.setRequestProperty("User-Agent", "Geyser-" + GeyserConnector.getInstance().getPlatformType().toString() + "/" + GeyserConnector.VERSION);
InputStream in = con.getInputStream();
Files.copy(in, Paths.get(fileLocation), StandardCopyOption.REPLACE_EXISTING); Files.copy(in, Paths.get(fileLocation), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) { } catch (Exception e) {
throw new AssertionError("Unable to download and save file: " + fileLocation + " (" + reqURL + ")", e); throw new AssertionError("Unable to download and save file: " + fileLocation + " (" + reqURL + ")", e);
@ -90,6 +92,7 @@ public class WebUtils {
HttpURLConnection con = (HttpURLConnection) url.openConnection(); HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST"); con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "text/plain"); con.setRequestProperty("Content-Type", "text/plain");
con.setRequestProperty("User-Agent", "Geyser-" + GeyserConnector.getInstance().getPlatformType().toString() + "/" + GeyserConnector.VERSION);
con.setDoOutput(true); con.setDoOutput(true);
OutputStream out = con.getOutputStream(); OutputStream out = con.getOutputStream();