Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions code/src/main/java/com/codeforces/commons/io/http/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public final class HttpRequest {

private long maxSizeBytes = FileUtil.BYTES_PER_GB;

private static final ThreadLocal<Map<String, Object>> threadLocalSettings
= ThreadLocal.withInitial(HashMap::new);

@Nonnull
public static HttpRequest create(String url, Object... parameters) {
return new HttpRequest(url, parameters);
Expand Down Expand Up @@ -546,8 +549,11 @@ private String appendGetParametersToUrl(String url) {
}

@SuppressWarnings("OverlyComplexMethod")
private static String[] validateAndEncodeParameters(String url, Object... parameters) {
if (!UrlUtil.isValidUrl(url)) {
private String[] validateAndEncodeParameters(String url, Object... parameters) {
boolean skipIsValidUrlCheck = Boolean.TRUE.equals(
threadLocalSettings.get().get("skipIsValidUrlCheck"));

if (!skipIsValidUrlCheck && !UrlUtil.isValidUrl(url)) {
throw new IllegalArgumentException('\'' + url + "' is not a valid URL.");
}

Expand Down Expand Up @@ -831,6 +837,11 @@ static <K, V> Map<K, List<V>> getDeepUnmodifiableMap(Map<K, List<V>> map) {
return Collections.unmodifiableMap(copy);
}

@SuppressWarnings("unused")
public static void putThreadLocalSetting(String key, Object value) {
threadLocalSettings.get().put(key, value);
}

static {
System.setProperty("http.keepAlive", "true");
}
Expand Down
Loading