diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala index 62ef2bc..7e87795 100644 --- a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala +++ b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala @@ -204,7 +204,7 @@ class HttpURLConnectionBackend private ( .flatMap { case (k, vv) => vv.asScala.map((k, _)) } val contentEncoding = Option(c.getHeaderField(ContentEncodingHeader)) val code = c.getResponseCode - val wrappedIs = wrapInput(contentEncoding, is) + val wrappedIs = wrapInput(contentEncoding, handleNullInput(is)) val body = if (codeIsSuccess(code)) { Right(readResponseBody(wrappedIs, responseAs)) } else { @@ -247,6 +247,12 @@ class HttpURLConnectionBackend private ( } } + private def handleNullInput(is: InputStream): InputStream = + if (is == null) + new ByteArrayInputStream(Array.empty[Byte]) + else + is + private def wrapInput(contentEncoding: Option[String], is: InputStream): InputStream = contentEncoding.map(_.toLowerCase) match { |