Skip to content

Commit 2a5954f

Browse files
committed
GH-5723: cleanup and polishing
Apache HttpClient Factory - Removed the unconditional evictIdleConnections(...) call - Added a guard so idle eviction is only configured when idleConnectionTimeoutMs > 0 - Also removed the duplicate evictExpiredConnections() that was present in the original SparqlProtocolSession Case-insensitive match: replaced startsWith("charset=") with regionMatches(true, 0, "charset=", 0, 8) — the true flag makes it case-insensitive, so CHARSET=, Charset=, etc. all match. 2. Quote stripping: after extracting the value, checks for surrounding double-quotes and strips them, handling charset="UTF-8". HttpUtils UnsupportedCharsetException is a subclass of IllegalArgumentException, so catching IllegalArgumentException covers both it and IllegalCharsetNameException in one clause — no need for multiple catches
1 parent cd0af8f commit 2a5954f

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

core/http/client-apache5/src/main/java/org/eclipse/rdf4j/http/client/apache5/ApacheHC5RDF4JHttpClientFactory.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ public RDF4JHttpClient create(RDF4JHttpClientConfig config) {
104104
.evictExpiredConnections()
105105
.setConnectionManager(connectionManager)
106106
.setDefaultRequestConfig(requestConfig)
107-
.evictExpiredConnections()
108-
.evictIdleConnections(TimeValue.ofMilliseconds(config.getIdleConnectionTimeoutMs()))
109107
.useSystemProperties()
110-
.setRetryStrategy(new RDF4JRetryStrategy(config.getMaxConnectionsPerRoute()))
111-
.setRedirectStrategy(DefaultRedirectStrategy.INSTANCE);
108+
.setRetryStrategy(new RDF4JRetryStrategy(config.getMaxConnectionsPerRoute()));
109+
110+
if (config.getIdleConnectionTimeoutMs() > 0) {
111+
builder.evictIdleConnections(TimeValue.ofMilliseconds(config.getIdleConnectionTimeoutMs()));
112+
}
113+
114+
builder.setRedirectStrategy(DefaultRedirectStrategy.INSTANCE);
112115

113116
if (!config.getDefaultHeaders().isEmpty()) {
114117
List<BasicHeader> defaultHeaders = config.getDefaultHeaders()

core/http/client-api/src/main/java/org/eclipse/rdf4j/http/client/spi/HttpUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static Charset parseCharset(String contentType, Charset defaultCharset)
9090
}
9191
try {
9292
return Charset.forName(name);
93-
} catch (UnsupportedCharsetException e) {
93+
} catch (IllegalArgumentException e) {
9494
return defaultCharset;
9595
}
9696
}

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,14 @@ Optional<Charset> getResponseCharset(HttpResponse response) {
11731173
for (HttpHeader header : headers) {
11741174
for (String part : header.getValue().split(";")) {
11751175
String trimmed = part.trim();
1176-
if (trimmed.startsWith("charset=")) {
1176+
if (trimmed.regionMatches(true, 0, "charset=", 0, "charset=".length())) {
11771177
String charsetName = trimmed.substring("charset=".length()).trim();
1178+
// Strip optional surrounding quotes (e.g. charset="UTF-8")
1179+
if (charsetName.length() >= 2
1180+
&& charsetName.charAt(0) == '"'
1181+
&& charsetName.charAt(charsetName.length() - 1) == '"') {
1182+
charsetName = charsetName.substring(1, charsetName.length() - 1);
1183+
}
11781184
try {
11791185
Charset charset = Charset.forName(charsetName);
11801186
logger.debug("response charset is {}", charset);

0 commit comments

Comments
 (0)