aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-backend
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-12-06 20:43:31 +0100
committeradamw <adam@warski.org>2017-12-06 20:43:31 +0100
commit3fb284c3c8849baa0f7b0d34ee9be78af7935bb6 (patch)
tree7231538c4dea18f7fec658bb421b2315a43180a3 /async-http-client-backend
parenta70053c72809c2588716c371a4d4f2a7404106d6 (diff)
downloadsttp-3fb284c3c8849baa0f7b0d34ee9be78af7935bb6.tar.gz
sttp-3fb284c3c8849baa0f7b0d34ee9be78af7935bb6.tar.bz2
sttp-3fb284c3c8849baa0f7b0d34ee9be78af7935bb6.zip
#53: using proper encoding when reading the response body
Diffstat (limited to 'async-http-client-backend')
-rw-r--r--async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala5
1 files changed, 4 insertions, 1 deletions
diff --git a/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
index 39c2b30..885e5a9 100644
--- a/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
+++ b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
@@ -270,7 +270,10 @@ abstract class AsyncHttpClientBackend[R[_], S](asyncHttpClient: AsyncHttpClient,
Try(())
case ResponseAsString(enc) =>
- Try(response.getResponseBody(Charset.forName(enc)))
+ val charset = Option(response.getHeader(ContentTypeHeader))
+ .flatMap(encodingFromContentType)
+ .getOrElse(enc)
+ Try(response.getResponseBody(Charset.forName(charset)))
case ResponseAsByteArray =>
Try(response.getResponseBodyAsBytes)