Use client-side http2 in akka-http_2.13 v10.1.12

Can anyone tell me what is the correct way to launch a http2 request with akka-http?
The doc website says I have to

Http.get(system)
        .connectionTo("127.0.0.1")
        .toPort(8443)
        .http2();

But in the akka-http version I use (akka-http_2.13 v10.1.12) there isn’t a method called connectionTo() in the akka.http.javadsl.Http class. (Plus I don’t know why the official javadoc doesn’t include akka-http_2.13 so it’s super hard to find any documentation)

I’m trying to launch http2 requests because I’m stuck on this error after migrating from akka-http_2.11 to akka-http_2.13, and I’m guessing it might because the server I’m sending requests to default with http2:

[ERROR] [07/08/2021 05:58:57.732] [graph-api-akka.actor.default-dispatcher-19] [akka://graph-api/system/Materializers/StreamSupervisor-2/flow-6-0-PoolFlow] Error in stage [akka.http.impl.engine.client.OutgoingConnectionBlueprint$PrepareResponse@25f31b7]: The server-side HTTP version is not supported
akka.http.scaladsl.model.IllegalResponseException: The server-side HTTP version is not supported
     at akka.http.impl.engine.client.OutgoingConnectionBlueprint$PrepareResponse$$anon$3.onPush(OutgoingConnectionBlueprint.scala:191)
     at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
     at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423)
     at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:625)
     ...

And it is really painful for me to debug. The API server I’m requesting, Facebook Graph API, should support both http1.1 and http2. So I can’t figure out why I got The server-side HTTP version is not supported. Or is there anything I can do in my akka-http code to force the requests to be http1.1?

Thank you so much for your time to help!

Hi @timlee0119,

you will have to use the latest version to get HTTP/2 client support. Try with 10.2.4 or 10.2.5-M1.

Johannes

Hi @jrudolph,

Thank you so much for your prompt reply, could you also hint me on how I should solve this error?

[ERROR] [07/09/2021 11:18:52.996] [graph-api-akka.actor.default-dispatcher-8] [akka://graph-api/system/Materializers/StreamSupervisor-2/flow-6-0-PoolFlow] Error in stage [akka.http.impl.engine.client.OutgoingConnectionBlueprint$PrepareResponse@64046ed6]: The server-side HTTP version is not supported
akka.http.scaladsl.model.IllegalResponseException: The server-side HTTP version is not supported
	at akka.http.impl.engine.client.OutgoingConnectionBlueprint$PrepareResponse$$anon$3.onPush(OutgoingConnectionBlueprint.scala:191)
	at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
	at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423)
	at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:625)
	at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:502)
	at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:600)
	at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:769)
	at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:784)
	at akka.actor.Actor.aroundReceive(Actor.scala:537)
	at akka.actor.Actor.aroundReceive$(Actor.scala:535)
	at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:691)
	at akka.actor.ActorCell.receiveMessage(ActorCell.scala:577)
	at akka.actor.ActorCell.invoke(ActorCell.scala:547)
	at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:270)
	at akka.dispatch.Mailbox.run(Mailbox.scala:231)
	at akka.dispatch.Mailbox.exec(Mailbox.scala:243)
	at java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

I used packet sniffer and sent the exact same request using curl to the server, and the server can respond normally. So I think this might be Akka parsing problem. But it is really hard to trace how Akka parse the result and what caused the error.

This is the raw request:
"User-Agent: akka-http/10.1.12" 'https://graph.facebook.com/v5.0/22092443056?fields=id&access_token=xyz&appsecret_proof=xyz'

This is the response I got from curl:

< HTTP/1.1 200 OK
< ETag: “0d5df398702dc0264c68d2e4e3d981d1631922a7”
< Content-Type: application/json; charset=UTF-8
< Vary: Origin
< Vary: Accept-Encoding
< x-app-usage: {“call_count”:0,“total_cputime”:0,“total_time”:77}
< x-fb-rlafr: 0
< Access-Control-Allow-Origin: *
< facebook-api-version: v5.0
< Strict-Transport-Security: max-age=15552000; preload
< Pragma: no-cache
< Cache-Control: private, no-cache, no-store, must-revalidate
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< x-fb-request-id: *********************
< x-fb-trace-id: *****************
< x-fb-rev: ***********
< X-FB-Debug: *************
< Date: Fri, 09 Jul 2021 04:02:22 GMT
< Transfer-Encoding: chunked
< Alt-Svc: h3-29=":443"; ma=3600,h3-27=":443"; ma=3600
< Connection: keep-alive

You can set akka.http.client.log-unencrypted-network-bytes = 100 to see what’s actually sent and received. The error probably means that you are connecting against a server that doesn’t respond with a HTTP/1.1 response.

When Travis CI - Test and Deploy with Confidence has run through, you could also check with the latest snapshot which now includes an encoding of the first bytes of the received response in the error message.

Thank you so much @jrudolph
I’ve solved the “The server-side HTTP version is not supported” problem, turns out the root cause was that I need to use cachedHostConnectionPoolHttps to query https endpoint instead of cachedHostConnectionPool.

2 Likes