Hello everyone!
I try to understand how the transparent HEAD request handling in Akka 2.4.6
behaves. According to the documentation I thought the following tests would
pass:
class Spec extends WordSpec with Matchers with ScalatestRouteTest {
val chunkedEntityByteStrings = List("Hello", " ", "world").map(s =>
ByteString(s.getBytes))
val routes =
head {
path("endpoint") {
complete {
HttpResponse(entity = HttpEntity.Chunked.fromData(ContentType(
MediaTypes.`application/octet-stream`), Source.fromIterator(() =>
chunkedEntityByteStrings.iterator)))
}
}
} ~
get {
path("endpoint") {
complete {
HttpResponse(entity = HttpEntity.Chunked.fromData(
ContentType(MediaTypes.`application/octet-stream`),
Source.fromIterator(() => chunkedEntityByteStrings.iterator)))
}
}
}
"The service" should {
"return a chunked entity on GET" in {
Get("/endpoint") ~> routes ~> check {
responseAs[String] shouldEqual "Hello world"
}
}
"return an empty entity on HEAD" in {
Head("/endpoint") ~> routes ~> check {
responseAs[String] shouldEqual "Hello world" // why does this pass?
responseEntity should equal(HttpEntity.Empty) // why does this fail?
}
}
}
}
And the "real" behavior is even stranger. curl'ing the GET endpoint behaves
as expected, HEAD requests get aborted by the server after transmitting the
header:
Aborting tcp connection because of upstream failure: No elements passed in
the last 1 minute.
totes
akka.stream.impl.Timers$IdleTimeoutBidi$$anon$7.onTimer(Timers.scala:160)
totes
akka.stream.stage.TimerGraphStageLogic.akka$stream$stage$TimerGraphStageLogic$$onInternalTimer(GraphStage.scala:1124)
totes
akka.stream.stage.TimerGraphStageLogic$$anonfun$akka$stream$stage$TimerGraphStageLogic$$getTimerAsyncCallback$1.apply(GraphStage.scala:1113)
totes
akka.stream.stage.TimerGraphStageLogic$$anonfun$akka$stream$stage$TimerGraphStageLogic$$getTimerAsyncCallback$1.apply(GraphStage.scala:1113)
totes
akka.stream.impl.fusing.GraphInterpreter.runAsyncInput(GraphInterpreter.scala:569)
totes
akka.stream.impl.fusing.GraphInterpreterShell.receive(ActorGraphInterpreter.scala:420)
totes
akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:604)
totes
akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:619)
totes akka.actor.Actor$class.aroundReceive(Actor.scala:482)
totes
akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:530)
totes akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
totes akka.actor.ActorCell.invoke(ActorCell.scala:495)
totes akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
totes akka.dispatch.Mailbox.run(Mailbox.scala:224)
totes akka.dispatch.Mailbox.exec(Mailbox.scala:234)
totes scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
totes
scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
totes
scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
totes
scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Which looks on the client/curl side like:
curl -X HEAD --raw -v "http://localhost:8080/endpoint"
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> HEAD /endpoint HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: akka-http/2.4.6
< Date: Fri, 20 May 2016 23:13:58 GMT
< Transfer-Encoding: chunked
< Content-Type: application/octet-stream
<
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
Why is the 'real' behavior that way? Is the Flow started but not canceled
keeping the HTTP connection open?
Thanks,
Sebastian
--
>>>>>>>>>> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.