@@ -35,7 +35,9 @@ const assert = std.debug.assert;
3535const use_vectors = builtin .zig_backend != .stage2_x86_64 ;
3636
3737const Client = @This ();
38- const proto = http .protocol ;
38+ const proto = std .http .protocol ;
39+
40+ const tls23 = @import ("tls" );
3941
4042const Loop = @import ("jsruntime" ).Loop ;
4143const tcp = @import ("tcp.zig" );
@@ -217,7 +219,7 @@ pub const ConnectionPool = struct {
217219pub const Connection = struct {
218220 stream : Stream ,
219221 /// undefined unless protocol is tls.
220- tls_client : if (! disable_tls ) * std . crypto . tls . Client else void ,
222+ tls_client : if (! disable_tls ) * tls23 . Connection ( Stream ) else void ,
221223
222224 /// The protocol that this connection is using.
223225 protocol : Protocol ,
@@ -246,12 +248,12 @@ pub const Connection = struct {
246248 pub const Protocol = enum { plain , tls };
247249
248250 pub fn readvDirectTls (conn : * Connection , buffers : []std.posix.iovec ) ReadError ! usize {
249- return conn .tls_client .readv (conn . stream , buffers ) catch | err | {
251+ return conn .tls_client .readv (buffers ) catch | err | {
250252 // https://github.com/ziglang/zig/issues/2473
251253 if (mem .startsWith (u8 , @errorName (err ), "TlsAlert" )) return error .TlsAlert ;
252254
253255 switch (err ) {
254- error .TlsConnectionTruncated , error . TlsRecordOverflow , error .TlsDecodeError , error . TlsBadRecordMac , error . TlsBadLength , error . TlsIllegalParameter , error .TlsUnexpectedMessage = > return error .TlsFailure ,
256+ error .TlsRecordOverflow , error .TlsBadRecordMac , error .TlsUnexpectedMessage = > return error .TlsFailure ,
255257 error .ConnectionTimedOut = > return error .ConnectionTimedOut ,
256258 error .ConnectionResetByPeer , error .BrokenPipe = > return error .ConnectionResetByPeer ,
257259 else = > return error .UnexpectedReadFailure ,
@@ -344,7 +346,7 @@ pub const Connection = struct {
344346 }
345347
346348 pub fn writeAllDirectTls (conn : * Connection , buffer : []const u8 ) WriteError ! void {
347- return conn .tls_client .writeAll (conn . stream , buffer ) catch | err | switch (err ) {
349+ return conn .tls_client .writeAll (buffer ) catch | err | switch (err ) {
348350 error .BrokenPipe , error .ConnectionResetByPeer = > return error .ConnectionResetByPeer ,
349351 else = > return error .UnexpectedWriteFailure ,
350352 };
@@ -412,7 +414,7 @@ pub const Connection = struct {
412414 if (disable_tls ) unreachable ;
413415
414416 // try to cleanly close the TLS connection, for any server that cares.
415- _ = conn .tls_client .writeEnd ( conn . stream , "" , true ) catch {};
417+ conn .tls_client .close ( ) catch {};
416418 allocator .destroy (conn .tls_client );
417419 }
418420
@@ -1376,13 +1378,13 @@ pub fn connectTcp(client: *Client, host: []const u8, port: u16, protocol: Connec
13761378 if (protocol == .tls ) {
13771379 if (disable_tls ) unreachable ;
13781380
1379- conn .data .tls_client = try client .allocator .create (std . crypto . tls . Client );
1381+ conn .data .tls_client = try client .allocator .create (tls23 . Connection ( Stream ) );
13801382 errdefer client .allocator .destroy (conn .data .tls_client );
13811383
1382- conn .data .tls_client .* = std . crypto . tls . Client . init (stream , client . ca_bundle , host ) catch return error . TlsInitializationFailed ;
1383- // This is appropriate for HTTPS because the HTTP headers contain
1384- // the content length which is used to detect truncation attacks.
1385- conn . data . tls_client . allow_truncation_attacks = true ;
1384+ conn .data .tls_client .* = tls23 . client (stream , .{
1385+ . host = host ,
1386+ . root_ca = client . ca_bundle ,
1387+ }) catch return error . TlsInitializationFailed ;
13861388 }
13871389
13881390 client .connection_pool .addUsed (conn );
0 commit comments