问题描述
我正在尝试使用 Reactor Netty 编写一个简单的 HTTPS 代理。 因此,当它接收到 CONNECT 方法时,它应该使用 TcpClient 向所需的主机发出请求,并将结果返回给客户端。
我试过这样做:
void init() {
disposableServer server = HttpServer.create()
.host("localhost")
.port(8080)
.handle((request,response) -> {
if (request.method() == HttpMethod.CONNECT) {
return tcpClient(request,response);
}
} )
.bindNow();
server.ondispose()
.block();
}
Mono<Void> tcpClient(HttpServerRequest request,HttpServerResponse response) {
URL url;
try {
url = new URL("https://" + request.requestHeaders().get("host"));
} catch (MalformedURLException e) {
return Mono.error(e);
}
String connectResponse = "HTTP/1.0 200 Connection established\n" +
"\r\n";
return TcpClient.create()
.host(url.getHost())
.port(url.getPort())
.connect()
.flatMap(connection -> response.sendString(Mono.just(connectResponse))
.then(response.send(connection.inbound().receive()))
.then()
.doOnTerminate(() -> connection.dispose())
)
.then();
}
但是,我在日志中得到了 Connection reset
,而客户端得到了 SSL_ERROR_RX_RECORD_TOO_LONG
。
我做错了什么,如何实现?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)