Akka 2.4.3 cannot read response body when using http 1.0 request

133 views
Skip to first unread message

xiaog zh

unread,
Apr 5, 2016, 2:37:10 AM4/5/16
to Akka User List
Hi,
  Below is a whole unit test in my project, and it fails when using `HTTP/1.0` protocol, success when using `HTTP/1.1`. Can somebody help explain the reason?

// setup mock server
val json =
 
"""
    |{"result":true}
  """.stripMargin

val source = Source(ByteString(json) :: Nil)
val mockRoutes = path("test" / "proxy_chunked.do") {
 
get {
    complete
{
     
HttpResponse(StatusCodes.OK, entity = HttpEntity(ContentTypes.`application/json`, source))
   
}
 
}
} ~ complete {
 
HttpResponse(StatusCodes.NotFound)
}

val (_, host, port) = AkkaHttpTestUtils.temporaryServerHostnameAndPort()
val bindingFuture = Http().bindAndHandle(mockRoutes, host, port)

val request = HttpRequest(
 
HttpMethods.GET,
  uri
= s"http://${host}:${port}/test/proxy_chunked.do",
  protocol
= HttpProtocols.`HTTP/1.0`
)

val futureByteString = Http().singleRequest(request).map { resp =>
 
println("response returned")
  resp
.entity.dataBytes
} flatMap { source =>
  source
.runFold(ByteString.empty)((r, bs) => r ++ bs)
}
val byteString = Await.result(futureByteString, 10 seconds)
byteString
.utf8String shouldEqual (json)


Viktor Klang

unread,
Apr 5, 2016, 3:44:37 AM4/5/16
to Akka User List

Could you include the error?

--
Cheers,

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

xiaog zh

unread,
Apr 5, 2016, 4:17:42 AM4/5/16
to Akka User List
debug level logs:

INFO - akka.event.slf4j.Slf4jLogger - Slf4jLogger started
DEBUG - akka.event.EventStream - logger log1-Slf4jLogger started
DEBUG - akka.event.EventStream - Default Loggers started
DEBUG - com.typesafe.sslconfig.akka.AkkaSSLConfig - Initializing AkkaSSLConfig extension...
DEBUG - com.typesafe.sslconfig.akka.AkkaSSLConfig - buildHostnameVerifier: created hostname verifier: com.typesafe.sslconfig.ssl.DefaultHostnameVerifier@39a2fc30
DEBUG - akka.io.TcpListener - Successfully bound to /127.0.0.1:57407
DEBUG - akka.http.impl.engine.client.PoolInterfaceActor - (Re-)starting host connection pool to localhost:57407
DEBUG - akka.http.impl.engine.client.PoolSlot$SlotProcessor - become unconnected, from subscriber pending
DEBUG - akka.http.impl.engine.client.PoolSlot$SlotProcessor - become unconnected, from subscriber pending
DEBUG - akka.http.impl.engine.client.PoolSlot$SlotProcessor - become unconnected, from subscriber pending
DEBUG - akka.http.impl.engine.client.PoolSlot$SlotProcessor - become unconnected, from subscriber pending
DEBUG - akka.io.TcpOutgoingConnection - Attempting connection to [localhost/127.0.0.1:57407]
DEBUG - akka.io.TcpListener - New connection accepted
DEBUG - akka.io.TcpOutgoingConnection - Connection established to [localhost/127.0.0.1:57407]
INFO - akka.actor.LocalActorRef - Message [akka.io.Tcp$ResumeReading$] from Actor[akka://ProxyActorTest/user/StreamSupervisor-1/$$b#-1567866888] to Actor[akka://ProxyActorTest/system/IO-TCP/selectors/$a/1#1829940929] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
DEBUG - akka.http.impl.engine.client.PoolSlot$SlotProcessor - Slot 0 disconnected after regular connection close
response returned

Futures timed out after [10 seconds]
java.util.concurrent.TimeoutException: Futures timed out after [10 seconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219)
at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223)
at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:190)
at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
at scala.concurrent.Await$.result(package.scala:190)
at com.oneapm.mordor.actors.marathon.ProxyActorTest$$anonfun$1$$anonfun$apply$mcV$sp$3.apply$mcV$sp(ProxyActorTest.scala:160)
at com.oneapm.mordor.actors.marathon.ProxyActorTest$$anonfun$1$$anonfun$apply$mcV$sp$3.apply(ProxyActorTest.scala:122)
at com.oneapm.mordor.actors.marathon.ProxyActorTest$$anonfun$1$$anonfun$apply$mcV$sp$3.apply(ProxyActorTest.scala:122)

André

unread,
Apr 5, 2016, 6:14:30 AM4/5/16
to Akka User List
The mandatory connection closing in HTTP 1.0 doesn't seem to work with non-strict entities.

HttpResponse(StatusCodes.OK, entity = HttpEntity(ContentTypes.`application/json`, json)) works.

HttpResponse(StatusCodes.OK, entity = HttpEntity(ContentTypes.`application/json`, source), headers = Connection("close") :: Nil) produces the same failure when requested with HTTP 1.1.

Could you open a ticket?

Cheers
André

xiaog zh

unread,
Apr 5, 2016, 8:30:00 AM4/5/16
to Akka User List
https://github.com/akka/akka/issues/20236

Can somebody give me a little clue or even guide me get this problem fixed?

Konrad Malawski

unread,
Apr 5, 2016, 8:48:23 AM4/5/16
to Akka User List
Let's continue the discussion in the ticket.
As Viktor found, it'd seem the 1.0 spec simply does not support this though...?
--
Cheers,
Konrad 'ktoso' Malawski
Reply all
Reply to author
Forward
0 new messages