Skip to content

Commit 23b2077

Browse files
Merge pull request #97 from Codeforces/dev-mikemirzayanov
HttpRequest#putThreadLocalSetting
2 parents c7cf0aa + 44c6adb commit 23b2077

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

code/src/main/java/com/codeforces/commons/io/http/HttpRequest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public final class HttpRequest {
6363

6464
private long maxSizeBytes = FileUtil.BYTES_PER_GB;
6565

66+
private static final ThreadLocal<Map<String, Object>> threadLocalSettings
67+
= ThreadLocal.withInitial(HashMap::new);
68+
6669
@Nonnull
6770
public static HttpRequest create(String url, Object... parameters) {
6871
return new HttpRequest(url, parameters);
@@ -546,8 +549,11 @@ private String appendGetParametersToUrl(String url) {
546549
}
547550

548551
@SuppressWarnings("OverlyComplexMethod")
549-
private static String[] validateAndEncodeParameters(String url, Object... parameters) {
550-
if (!UrlUtil.isValidUrl(url)) {
552+
private String[] validateAndEncodeParameters(String url, Object... parameters) {
553+
boolean skipIsValidUrlCheck = Boolean.TRUE.equals(
554+
threadLocalSettings.get().get("skipIsValidUrlCheck"));
555+
556+
if (!skipIsValidUrlCheck && !UrlUtil.isValidUrl(url)) {
551557
throw new IllegalArgumentException('\'' + url + "' is not a valid URL.");
552558
}
553559

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

840+
@SuppressWarnings("unused")
841+
public static void putThreadLocalSetting(String key, Object value) {
842+
threadLocalSettings.get().put(key, value);
843+
}
844+
834845
static {
835846
System.setProperty("http.keepAlive", "true");
836847
}

0 commit comments

Comments
 (0)