From 6f2f151a99493dd5d9a4c6a0e41d6eeba711441b Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 18 Jul 2024 17:09:10 +0530 Subject: [PATCH] Cleaned up HttpConnection.Base class a bit --- .../java/org/jsoup/helper/HttpConnection.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java index 6324a80149..87e0f4d06d 100644 --- a/src/main/java/org/jsoup/helper/HttpConnection.java +++ b/src/main/java/org/jsoup/helper/HttpConnection.java @@ -394,20 +394,11 @@ public Connection postDataCharset(String charset) { } @SuppressWarnings("unchecked") - private static abstract class Base> implements Connection.Base { - private static final URL UnsetUrl; // only used if you created a new Request() - static { - try { - UnsetUrl = new URL("http://undefined/"); - } catch (MalformedURLException e) { - throw new IllegalStateException(e); - } - } - - URL url = UnsetUrl; - Method method = Method.GET; - Map> headers; - Map cookies; + private abstract static class Base> implements Connection.Base { + protected URL url; + protected Method method = Method.GET; + protected final Map> headers; + protected final Map cookies; private Base() { headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); @@ -426,7 +417,7 @@ private Base(Base copy) { @Override public URL url() { - if (url == UnsetUrl) + if (url == null) throw new IllegalArgumentException("URL not set. Make sure to call #url(...) before executing the request."); return url; } @@ -590,7 +581,6 @@ public static class Request extends HttpConnection.Base impl maxBodySizeBytes = 1024 * 1024 * 2; // 2MB followRedirects = true; data = new ArrayList<>(); - method = Method.GET; addHeader("Accept-Encoding", "gzip"); addHeader(USER_AGENT, DEFAULT_UA); parser = Parser.htmlParser();