Akka-http POST 结果 "The server-side HTTP version is not supported"

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

我在尝试使用 akka-http 向某个内部端点发出简单的 POST 请求时遇到问题。执行这段代码时:

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 ...

我遇到以下错误:

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

紧接着是以下日志:

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

作为我调试之旅的一部分,我使用 curl 对端点执行了相同的查询,这神奇地成功了(并以 HTTP/1.1 响应)。由于 HttpRequest(...) 默认使用 protocol = HttpProtocols.`HTTP/1.1`,我怀疑 akka-http 和其他端点之间协商的 HTTP 版本不正确。

当 akka-http 执行 POST 时,是否有可能以某种方式强制执行 HTTP 版本?或者关于为什么 curl 成功执行 POST 而 akka-http 没有的任何其他线索?请注意,问题仅在执行 POST 时出现,而不是 GET 时出现。

原来这个问题有一个非常奇怪的解决方案:不是直接连接到通过地址 http://foo/bar:8080 (using our internal DNS resolver), we connected indirectly to the endpoint using https://our-domain.com:443 连接到另一个端点。在那种情况下,一切都按预期工作。似乎 akka-http 因缺少 TLD 而受到某种困扰。