diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java index fccf509c6..2d26172a8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharPushConsumer.java @@ -37,6 +37,7 @@ import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.config.CharCodingConfig; import org.apache.hc.core5.http.nio.AsyncPushConsumer; import org.apache.hc.core5.http.nio.entity.AbstractCharDataConsumer; import org.apache.hc.core5.http.protocol.HttpContext; @@ -48,6 +49,19 @@ */ public abstract class AbstractCharPushConsumer extends AbstractCharDataConsumer implements AsyncPushConsumer { + private final Charset defaultCharset; + + public AbstractCharPushConsumer() { + this.defaultCharset = StandardCharsets.UTF_8; + } + + protected AbstractCharPushConsumer(final int bufSize, + final CharCodingConfig charCodingConfig) { + super(bufSize, charCodingConfig); + this.defaultCharset = charCodingConfig != null && charCodingConfig.getCharset() != null + ? charCodingConfig.getCharset() : StandardCharsets.UTF_8; + } + /** * Triggered to signal the beginning of data processing. * @@ -72,7 +86,7 @@ public final void consumePromise( } Charset charset = contentType != null ? contentType.getCharset() : null; if (charset == null) { - charset = StandardCharsets.US_ASCII; + charset = defaultCharset; } setCharset(charset); start(promise, response, contentType != null ? contentType : ContentType.DEFAULT_TEXT); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java index 825f93f72..eb39dbfaa 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AbstractCharResponseConsumer.java @@ -37,6 +37,7 @@ import org.apache.hc.core5.http.EntityDetails; import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.config.CharCodingConfig; import org.apache.hc.core5.http.nio.AsyncResponseConsumer; import org.apache.hc.core5.http.nio.entity.AbstractCharDataConsumer; import org.apache.hc.core5.http.protocol.HttpContext; @@ -51,6 +52,18 @@ public abstract class AbstractCharResponseConsumer extends AbstractCharDataConsumer implements AsyncResponseConsumer { private volatile FutureCallback resultCallback; + private final Charset defaultCharset; + + public AbstractCharResponseConsumer() { + this.defaultCharset = StandardCharsets.UTF_8; + } + + protected AbstractCharResponseConsumer(final int bufSize, + final CharCodingConfig charCodingConfig) { + super(bufSize, charCodingConfig); + this.defaultCharset = charCodingConfig != null && charCodingConfig.getCharset() != null + ? charCodingConfig.getCharset() : StandardCharsets.UTF_8; + } /** * Triggered to signal the beginning of data processing. @@ -90,7 +103,7 @@ public final void consumeResponse( } Charset charset = contentType != null ? contentType.getCharset() : null; if (charset == null) { - charset = StandardCharsets.US_ASCII; + charset = defaultCharset; } setCharset(charset); start(response, contentType != null ? contentType : ContentType.DEFAULT_TEXT);