Akka-http POST results in “The server-side HTTP version is not supported”

两盒软妹~` 提交于 2019-12-24 12:09:32

问题


I have an issue when trying to do a simple POST request to some internal endpoint using akka-http. When this piece of code is executed:

for {
      request <- Marshal(merchantTransactionRequest).to[RequestEntity]
      response <- Http().singleRequest(
        HttpRequest(
          method = HttpMethods.POST,
          uri = "http://foo/bar:8080",
          entity = request.withContentType(ContentTypes.`application/json`)
        )
      )
      ...
} yield ...

I get greeted with the following error:

akka.http.scaladsl.model.IllegalResponseException: The server-side HTTP version is not supported at akka.http.impl.engine.client.OutgoingConnectionBlueprint$PrepareResponse$$anon$1.onPush(OutgoingConnectionBlueprint.scala:191) ...

which is immediately preceded by the following log:

[0] </10.0.0.135:42610->foo:8080> pushing request to connection: POST bar Strict(508 bytes)

As part of my debugging journey, I executed the same query to the endpoint using curl, which magically succeeded (and responds with HTTP/1.1). Since HttpRequest(...) defaults to using protocol = HttpProtocols.`HTTP/1.1`, it is my suspicion that somehow the HTTP version negotiated between akka-http and this other endpoint is incorrect.

Is it possible to somehow enforce a HTTP version when akka-http does a POST? Or any other clue as to why curl succeeds doing the POST, while akka-http does not? Note that problem only occurs while doing POST's, not GET's.


回答1:


It turned out the problem had a very strange solution: Instead of connecting to directly connecting to the other endpoint through address http://foo/bar:8080 (using our internal DNS resolver), we connected indirectly to the endpoint using https://our-domain.com:443. Everything worked as expected in that case. It seems that akka-http is somehow troubled by the absence of a TLD.



来源:https://stackoverflow.com/questions/46407564/akka-http-post-results-in-the-server-side-http-version-is-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!