Proxy Requests Non-HTTP Do not send CONNECT requests

This commit is contained in:
wanghongenpin
2024-08-26 19:59:21 +08:00
parent debec047c9
commit 7b89af1401
4 changed files with 7 additions and 3 deletions

View File

@@ -189,8 +189,8 @@ class HttpProxyChannelHandler extends ChannelHandler<HttpRequest> {
if (httpRequest.method == HttpMethod.connect) {
await proxyChannel.write(httpRequest);
} else {
await HttpClients.connectRequest(hostAndPort, proxyChannel);
if (clientChannel.isSsl) {
await HttpClients.connectRequest(hostAndPort, proxyChannel);
await proxyChannel.secureSocket(channelContext, host: hostAndPort.host);
}
}

View File

@@ -134,7 +134,7 @@ class HttpRequest extends HttpMessage {
String path() {
try {
var requestPath = Uri.parse(requestUrl).path;
return requestPath.isEmpty ? "/" : requestPath;
return requestPath.isEmpty ? "" : requestPath;
} catch (e) {
return "/";
}

View File

@@ -50,7 +50,7 @@ class HttpClients {
HostAndPort connectHost = proxyInfo == null ? hostAndPort : HostAndPort.host(proxyInfo.host, proxyInfo.port!);
var channel = await client.connect(connectHost, channelContext);
if (proxyInfo != null) {
if (proxyInfo != null && hostAndPort.isSsl()) {
await connectRequest(hostAndPort, channel);
}

View File

@@ -89,6 +89,10 @@ class ProxyHelper {
..hostAndPort = hostAndPort;
request.processInfo ??= channelContext.processInfo;
if (request.method == HttpMethod.connect && !request.requestUrl.startsWith("http")) {
request.uri = hostAndPort.domain;
}
request.response = HttpResponse(status)
..headers.contentType = 'text/plain'
..headers.contentLength = message.codeUnits.length