我有一个HttpServer和一个HttpClient。如果我在任何一方使用Netty的HttpServerCodec和HttpObjectAggregator,我就会收到错误。
服务器代码
HttpServer server = HttpServer.create(opts -> opts.listen(8092).afterChannelInit(channelInit -> {
ChannelPipeline pipeline = channelInit.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(64*1024));
}));
server.newRouter(routes -> {
routes.post("/xmlvend", postHandler());
}).block(Duration.ofSeconds(30));
BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> postHandler() {
return (req, resp) -> {
req.requestHeaders().entries()
.forEach(entry -> log.debug(String.format("header [%s=>%s]", entry.getKey(), entry.getValue())));
return resp.sendString(req.receive().asByteArray().take(1).log("received").flatMap(data -> {
return Flux.just("Hello");
}));
};
}
客户端
HttpClient client = HttpClient.create(opts -> opts.connect(host, port).poolResources(pool).afterChannelInit(serverEndPoint));
ByteBuf reqContent = getTestRequest();
DefaultFullHttpRequest reqHeader = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, url, reqContent);
Mono<HttpClientResponse> rsp = client.request(HttpMethod.POST, url, (req) -> req.chunkedTransfer(true).addHeader("Content-Length", Integer.toString(reqHeader.content().capacity())).sendHeaders().send(Flux.just(reqContent)/*clientRequest -> clientRequest.onNext(reqHeader.content())*/));
rsp.subscribe().block();
serverEndPoint还包含HttpServerCodec和ObjectAggregator。 我尝试过使用HttpClientCodec,在管道中没有任何东西 尝试发送DefaultFullHttpRequest。 要么我得到异常,要么在客户端只读取1024字节。 我需要发送一个超过1024字节的分块请求。
由于