Skip to content

Commit 9723ff5

Browse files
committed
TLS connect proxy WIP
1 parent 7435274 commit 9723ff5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/http/client.zig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,15 @@ const SyncHandler = struct {
18081808
const socket = request._connection.?.socket;
18091809

18101810
const header = try request.buildConnectHeader();
1811-
try Conn.writeAll(socket, header);
1811+
// try Conn.writeAll(socket, header);
1812+
var tls_client = try tls.client(std.net.Stream{ .handle = socket }, .{
1813+
.host = request._connect_host,
1814+
.root_ca = request._client.root_ca,
1815+
.insecure_skip_verify = request._tls_verify_host == false,
1816+
.key_log_callback = tls.config.key_log.callback,
1817+
});
1818+
// defer tls_client.close() catch {}; // should we close it so a new client can be created on the socket for the destination tls connection?
1819+
try tls_client.writeAll(header);
18121820

18131821
var pos: usize = 0;
18141822
var reader = request.newReader();
@@ -1819,7 +1827,12 @@ const SyncHandler = struct {
18191827
// we only send CONNECT requests on newly established connections
18201828
// and maybeRetryOrErr is only for connections that might have been
18211829
// closed while being kept-alive
1822-
const n = try posix.read(socket, read_buf[pos..]);
1830+
// const n = try posix.read(socket, read_buf[pos..]);
1831+
// const n = switch (self.*) {
1832+
// .tls => |tls_client| try tls_client.read(buf),
1833+
// .plain => |socket| try posix.read(socket, buf),
1834+
// };
1835+
const n = try tls_client.read(read_buf[pos..]);
18231836
if (n == 0) {
18241837
return error.ConnectionResetByPeer;
18251838
}
@@ -2081,6 +2094,7 @@ const Reader = struct {
20812094
if (result.done == false) {
20822095
// CONNECT responses should not have a body. If the header is
20832096
// done, then the entire response should be done.
2097+
log.err(.http_client, "InvalidConnectResponse", .{ .unprocessed = result.unprocessed.? });
20842098
return error.InvalidConnectResponse;
20852099
}
20862100

0 commit comments

Comments
 (0)