Skip to content

Commit

Permalink
Cleaned up HttpConnection.Base class a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jul 18, 2024
1 parent c60259f commit 6f2f151
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/main/java/org/jsoup/helper/HttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,11 @@ public Connection postDataCharset(String charset) {
}

@SuppressWarnings("unchecked")
private static abstract class Base<T extends Connection.Base<T>> implements Connection.Base<T> {
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<String, List<String>> headers;
Map<String, String> cookies;
private abstract static class Base<T extends Connection.Base<T>> implements Connection.Base<T> {
protected URL url;
protected Method method = Method.GET;
protected final Map<String, List<String>> headers;
protected final Map<String, String> cookies;

private Base() {
headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Expand All @@ -426,7 +417,7 @@ private Base(Base<T> 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;
}
Expand Down Expand Up @@ -590,7 +581,6 @@ public static class Request extends HttpConnection.Base<Connection.Request> 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();
Expand Down

0 comments on commit 6f2f151

Please sign in to comment.