Skip to content

Commit 1ddd7db

Browse files
committed
minor refactor prep for tls
1 parent 878dbd8 commit 1ddd7db

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/http/client.zig

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -806,27 +806,12 @@ pub const Request = struct {
806806
log.warn(.http, "not implemented", .{ .feature = "async tls connect" });
807807
}
808808

809-
const is_proxy = self._client.isProxy();
810-
if ((is_proxy and self._proxy_secure) or (!self._client.isForwardProxy() and self._request_secure)) {
811-
if (self._connection_from_keepalive) {
812-
// If the connection came from the keepalive pool, than we already
813-
// have a TLS Connection.
814-
async_handler.conn.protocol = .{ .encrypted = .{ .conn = &connection.tls.?.nonblocking } };
815-
} else {
816-
std.debug.assert(connection.tls == null);
817-
async_handler.conn.protocol = .{
818-
.handshake = tls.nonblock.Client.init(.{
819-
.host = if (self._client.isConnectProxy()) self._request_host else self._connect_host, // looks wrong
820-
.root_ca = self._client.root_ca,
821-
.insecure_skip_verify = self._tls_verify_host == false,
822-
.key_log_callback = tls.config.key_log.callback,
823-
}),
824-
};
825-
}
826-
}
827-
828-
if (self._connection_from_keepalive) {
829-
// we're already connected
809+
if (self._connection_from_keepalive and
810+
((self._client.isProxy() and self._proxy_secure) or (!self._client.isForwardProxy() and self._request_secure)))
811+
{
812+
// If the connection came from the keepalive pool, than we already have a TLS Connection.
813+
async_handler.conn.protocol = .{ .encrypted = .{ .conn = &connection.tls.?.nonblocking } };
814+
// and we're already connected
830815
async_handler.pending_connect = false;
831816
return async_handler.conn.connected();
832817
}
@@ -1156,6 +1141,19 @@ fn AsyncHandler(comptime H: type) type {
11561141

11571142
result catch |err| return self.handleError("Connection failed", err);
11581143

1144+
const request = self.request;
1145+
if (request._request_secure) {
1146+
std.debug.assert(request._connection.?.tls == null);
1147+
self.conn.protocol = .{
1148+
.handshake = tls.nonblock.Client.init(.{
1149+
.host = request._request_host,
1150+
.root_ca = request._client.root_ca,
1151+
.insecure_skip_verify = request._tls_verify_host == false,
1152+
.key_log_callback = tls.config.key_log.callback,
1153+
}),
1154+
};
1155+
}
1156+
11591157
if (self.request.shouldProxyConnect()) {
11601158
self.state = .connect;
11611159
const header = self.request.buildConnectHeader() catch |err| {

0 commit comments

Comments
 (0)