From 525da1ef90c7b2d67ed0917c9c398c3989b4d64c Mon Sep 17 00:00:00 2001 From: Smyler Date: Sat, 14 Sep 2024 15:59:24 +0200 Subject: [PATCH] Use a dedicated user agent --- .../smyler/terramap/http/HttpStatusCodes.java | 85 ------------------- .../terramap/http/TerramapHttpClient.java | 5 +- 2 files changed, 4 insertions(+), 86 deletions(-) delete mode 100644 fabric/src/main/java/net/smyler/terramap/http/HttpStatusCodes.java diff --git a/fabric/src/main/java/net/smyler/terramap/http/HttpStatusCodes.java b/fabric/src/main/java/net/smyler/terramap/http/HttpStatusCodes.java deleted file mode 100644 index 52b27ba5..00000000 --- a/fabric/src/main/java/net/smyler/terramap/http/HttpStatusCodes.java +++ /dev/null @@ -1,85 +0,0 @@ -package net.smyler.terramap.http; - - -/** - * HTTP response codes. - * - * @see MDN documentation - */ -public final class HttpStatusCodes { - - // Information responses - public static final int HTTP_CONTINUE = 100; - public static final int HTTP_SWITCHING_PROTOCOLS = 101; - public static final int HTTP_PROCESSING = 102; - public static final int HTTP_EARLY_HINTS = 103; - - // Successful responses - public static final int HTTP_OK = 200; - public static final int HTTP_CREATED = 201; - public static final int HTTP_ACCEPTED = 202; - public static final int HTTP_NON_AUTHORITATIVE_INFORMATION = 203; - public static final int HTTP_NO_CONTENT = 204; - public static final int HTTP_RESET_CONTENT = 205; - public static final int HTTP_PARTIAL_CONTENT = 206; - public static final int HTTP_MULTI_STATUS = 207; - public static final int HTTP_ALREADY_REPORTED = 208; - public static final int HTTP_IM_USED = 209; - - // Redirection message - public static final int HTTP_MULTIPLE_CHOICES = 300; - public static final int HTTP_MOVED_PERMANENTLY = 301; - public static final int HTTP_FOUND = 302; - public static final int HTTP_SEE_OTHER = 303; - public static final int HTTP_NOT_MODIFIED = 304; - public static final int HTTP_USE_PROXY = 305; - public static final int HTTP_UNUSED = 306; - public static final int HTTP_TEMPORARY_REDIRECT = 307; - public static final int HTTP_PERMANENT_REDIRECT = 308; - - // Client error response - public static final int HTTP_BAD_REQUEST = 400; - public static final int HTTP_UNAUTHORIZED = 401; - public static final int HTTP_PAYMENT_REQUIRED = 402; - public static final int HTTP_FORBIDDEN = 403; - public static final int HTTP_NOT_FOUND = 404; - public static final int HTTP_METHOD_NOT_ALLOWED = 405; - public static final int HTTP_NOT_ACCEPTABLE = 406; - public static final int HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; - public static final int HTTP_REQUEST_TIMEOUT = 408; - public static final int HTTP_CONFLICT = 409; - public static final int HTTP_GONE = 410; - public static final int HTTP_LENGTH_REQUIRED = 411; - public static final int HTTP_PRECONDITION_FAILED = 412; - public static final int HTTP_REQUEST_ENTITY_TOO_LARGE = 413; - public static final int HTTP_REQUEST_URI_TOO_LONG = 414; - public static final int HTTP_UNSUPPORTED_MEDIA_TYPE = 415; - public static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; - public static final int HTTP_EXPECTATION_FAILED = 417; - public static final int HTTP_I_M_A_TEAPOT = 418; - public static final int HTTP_UNPROCESSABLE_ENTITY = 422; - public static final int HTTP_LOCKED = 423; - public static final int HTTP_FAILED_DEPENDENCY = 424; - public static final int HTTP_TOO_EARLY = 425; - public static final int HTTP_UPGRADE_REQUIRED = 426; - public static final int HTTP_PRECONDITION_REQUIRED = 428; - public static final int HTTP_TOO_MANY_REQUESTS = 429; - public static final int HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; - public static final int HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 432; - - // Server error response - public static final int HTTP_INTERNAL_SERVER_ERROR = 500; - public static final int HTTP_NOT_IMPLEMENTED = 501; - public static final int HTTP_BAD_GATEWAY = 502; - public static final int HTTP_SERVICE_UNAVAILABLE = 503; - public static final int HTTP_GATEWAY_TIMEOUT = 504; - public static final int HTTP_HTTP_VERSION_NOT_SUPPORTED = 505; - public static final int HTTP_VARIANT_ALSO_NEGOTIATES = 506; - public static final int HTTP_INSUFFICIENT_STORAGE = 507; - public static final int HTTP_LOOP_DETECTED = 508; - public static final int HTTP_NOT_EXTENDED = 510; - public static final int HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; - - private HttpStatusCodes() {} - -} diff --git a/fabric/src/main/java/net/smyler/terramap/http/TerramapHttpClient.java b/fabric/src/main/java/net/smyler/terramap/http/TerramapHttpClient.java index cccce5df..73d09041 100644 --- a/fabric/src/main/java/net/smyler/terramap/http/TerramapHttpClient.java +++ b/fabric/src/main/java/net/smyler/terramap/http/TerramapHttpClient.java @@ -1,6 +1,7 @@ package net.smyler.terramap.http; import net.smyler.smylib.Strings; +import net.smyler.terramap.Terramap; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,6 +25,7 @@ import static java.util.Arrays.stream; import static java.util.Objects.requireNonNull; import static net.smyler.smylib.Objects.optionalBiMapSupplier; +import static net.smyler.smylib.SmyLib.getGameClient; import static net.smyler.terramap.http.CacheStatistics.CacheType.ERROR; import static net.smyler.terramap.http.HttpStatusCodes.*; import static net.smyler.smylib.Strings.isNullOrEmpty; @@ -35,7 +37,8 @@ public class TerramapHttpClient implements CachingHttpClient { private final ForkJoinPool semaphoreAcquireExecutor = new ForkJoinPool(1, HttpWorkerThread::new, this::unhandledException, true); private final AtomicLong workerCounter = new AtomicLong(0); - private static final String USER_AGENT = "Experimental Terramap version https://github.com/SmylerMC/terramap"; + private static final String USER_AGENT = UserAgent.buildUserAgent(getGameClient(), Terramap.instance()); + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter .ofPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH) .withZone(ZoneId.of("GMT"));