diff options
author | adamw <adam@warski.org> | 2017-12-06 20:43:31 +0100 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-12-06 20:43:31 +0100 |
commit | 3fb284c3c8849baa0f7b0d34ee9be78af7935bb6 (patch) | |
tree | 7231538c4dea18f7fec658bb421b2315a43180a3 /async-http-client-backend/src/main/scala/com | |
parent | a70053c72809c2588716c371a4d4f2a7404106d6 (diff) | |
download | sttp-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/src/main/scala/com')
-rw-r--r-- | async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala | 5 |
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) |