diff options
author | Chris Birchall <chris.birchall@gmail.com> | 2017-09-25 13:28:44 +0100 |
---|---|---|
committer | Chris Birchall <chris.birchall@gmail.com> | 2017-09-25 13:36:24 +0100 |
commit | e3a37944c330f96ae692ee1c84fcf1c6e881e821 (patch) | |
tree | c4db9e0106253e0b933db2bec8102c08f9e49ece /tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | |
parent | e515b860a3fe33368d073ae0af419c0bc1928bed (diff) | |
download | sttp-e3a37944c330f96ae692ee1c84fcf1c6e881e821.tar.gz sttp-e3a37944c330f96ae692ee1c84fcf1c6e881e821.tar.bz2 sttp-e3a37944c330f96ae692ee1c84fcf1c6e881e821.zip |
Add failing test to reproduce the issue
I'm not sure if there are other scenarios in which
HTTPUrlConnection#getInputStream() can return null,
but this is the one that I found.
Diffstat (limited to 'tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index de033df..a2b9505 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -170,6 +170,17 @@ class BasicTests akka.pattern.after(1.second, using = actorSystem.scheduler)( Future.successful("Done")) } + } ~ path("empty_unauthorized_response") { + post { + import akka.http.scaladsl.model._ + complete( + HttpResponse( + status = StatusCodes.Unauthorized, + headers = Nil, + entity = HttpEntity.Empty, + protocol = HttpProtocols.`HTTP/1.1` + )) + } } override def port = 51823 @@ -220,6 +231,7 @@ class BasicTests multipartTests() redirectTests() timeoutTests() + emptyResponseTests() def parseResponseTests(): Unit = { name should "parse response as string" in { @@ -664,6 +676,18 @@ class BasicTests request.send().force().unsafeBody should be("Done") } } + + def emptyResponseTests(): Unit = { + val postEmptyResponse = sttp + .post(uri"$endpoint/empty_unauthorized_response") + .body("{}") + .contentType("application/json") + + name should "parse an empty error response as empty string" in { + val response = postEmptyResponse.send().force() + response.body should be(Left("")) + } + } } override protected def afterAll(): Unit = { |