这是可能的,但很费劲。我已经这样做了,但是我不能在这里发布完整的代码,因为它是私人的。
相关AKKA代码确实这是HttpRequestParser
大部分的代码是包私有的,所以你需要编写一个辅助类自己在akka.http
包去访问它。
该代码将是这个样子:
package akka.http
/**
* This class gives us access to Akka's [[akka.http.impl.engine.parsing.HttpRequestParser]].
*
* It is in the akka package, as most of Akka's parsing code is package-private.
*
* @see [[akka.http.impl.engine.server.HttpServerBluePrint]]
*/
class HttpRequestParserHelper()(
implicit system: ActorSystem,
materializer: Materializer) {
def unmarshalRequest(wireFormat: Array[Byte]): HttpRequest = {
val input = ByteString(wireFormat)
val requestFuture = Source.single(input)
.via(requestParsingFlow())
.runWith(Streams.getSingleElement)
.transform(identity, e =>
new IOException("Error unmarshalling request", e))
Await.result(requestFuture, 10.seconds)
}
/**
* An Akka Flow which parses incoming ByteStrings and emits HttpRequests.
*
* This code was copied from [[akka.http.impl.engine.server.HttpServerBluePrint]]
*/
private def requestParsingFlow(): Flow[ByteString, HttpRequest, Any] = {
...
}
}
填写requestParsingFlow
从AKKA源代码,删除直到它编译这是不适用的位。
输入数据需要从你的问题是TCP流的数据,即选项(3)。
祝你好运!
你的问题是什么? – TNW
@TNW,我特别编辑了我的问题。你怎么看? – Hibuki
下面是[一些](https://github.com/akka/akka/blob/f008a932c381013f6060ee00a731862bafed2be7/akka-http-core/src/test/scala/akka/http/impl/engine/client/TlsEndpointVerificationSpec.scala)从阿卡-HTTP单元的例子](https://github.com/akka/akka/blob/f008a932c381013f6060ee00a731862bafed2be7/akka-http-core/src/test/scala/akka/http/impl/engine/client/TlsEndpointVerificationSpec.scala)测试,他们可能会帮助 – Hibuki