diff options
author | Chris Birchall <chris.birchall@gmail.com> | 2017-09-25 13:35:30 +0100 |
---|---|---|
committer | Chris Birchall <chris.birchall@gmail.com> | 2017-09-25 13:36:24 +0100 |
commit | b0722d8def38e7f4a133b54d5b8d56558f6237c9 (patch) | |
tree | 0e8ad1144f642f52eaa825489934beb7113d76ce | |
parent | e3a37944c330f96ae692ee1c84fcf1c6e881e821 (diff) | |
download | sttp-b0722d8def38e7f4a133b54d5b8d56558f6237c9.tar.gz sttp-b0722d8def38e7f4a133b54d5b8d56558f6237c9.tar.bz2 sttp-b0722d8def38e7f4a133b54d5b8d56558f6237c9.zip |
Add a null check for result of getInputStream()
-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 { |