@@ -242,7 +242,7 @@ pub const Client = struct {
242242
243243 fn isProxyTLS (self : * const Client ) bool {
244244 const proxy = self .http_proxy orelse return false ;
245- return std .mem . eql ( u8 , proxy .scheme , "https" );
245+ return std .ascii . eqlIgnoreCase ( proxy .scheme , "https" );
246246 }
247247};
248248
@@ -328,7 +328,7 @@ const Connection = struct {
328328 const TLSClient = union (enum ) {
329329 blocking : tls .Connection (std .net .Stream ),
330330 blocking_tls_in_tls : struct {
331- proxy : tls .Connection (std .net .Stream ),
331+ proxy : tls .Connection (std .net .Stream ), // Note, self-referential field. Proxy should be pinned in memory.
332332 destination : tls .Connection (* tls .Connection (std .net .Stream )),
333333 },
334334 nonblocking : tls.nonblock.Connection ,
@@ -688,37 +688,33 @@ pub const Request = struct {
688688 var proxy_conn : SyncHandler.Conn = .{ .plain = self ._connection .? .socket };
689689
690690 if (is_proxy_tls ) {
691-
692- // create an underlying TLS stream with the proxy
691+ // Create an underlying TLS stream with the proxy
693692 var proxy_tls_config = tls_config ;
694693 proxy_tls_config .host = self ._connect_host ;
695694 var proxy_conn_tls = try tls .client (std.net.Stream { .handle = socket }, proxy_tls_config );
696695 proxy_conn = .{ .tls = & proxy_conn_tls };
697696 }
698697
699- // connect to the proxy
698+ // Connect to the proxy
700699 try SyncHandler .connect (self , & proxy_conn );
701700
702701 if (is_proxy_tls ) {
703702 if (self ._secure ) {
704-
705- // if secure endpoint, create the main TLS stream
706- // encapsulated into the TLS stream proxy
707- const tls_in_tls = try tls .client (proxy_conn .tls , tls_config );
703+ // If secure endpoint, create the main TLS stream encapsulated into the TLS stream proxy
708704 self ._connection .? .tls = .{
709705 .blocking_tls_in_tls = .{
710706 .proxy = proxy_conn .tls .* ,
711- .destination = tls_in_tls ,
707+ .destination = undefined ,
712708 },
713709 };
710+ const proxy = & self ._connection .? .tls .? .blocking_tls_in_tls .proxy ;
711+ self ._connection .? .tls .? .blocking_tls_in_tls .destination = try tls .client (proxy , tls_config );
714712 } else {
715-
716- // otherwise, just use the TLS stream proxy
713+ // Otherwise, just use the TLS stream proxy
717714 self ._connection .? .tls = .{ .blocking = proxy_conn .tls .* };
718715 }
719716 }
720717 }
721-
722718 if (self ._secure and ! is_proxy_tls ) {
723719 self ._connection .? .tls = .{
724720 .blocking = try tls .client (std.net.Stream { .handle = socket }, tls_config ),
@@ -1947,16 +1943,10 @@ const SyncHandler = struct {
19471943
19481944 fn sendRequest (self : * Conn , header : []const u8 , body : ? []const u8 ) ! void {
19491945 switch (self .* ) {
1950- .tls = > | _ | {
1951- try self .writeAll (header );
1952- if (body ) | b | {
1953- try self .writeAll (b );
1954- }
1955- },
1956- .tls_in_tls = > | _ | {
1957- try self .writeAll (header );
1946+ inline .tls , .tls_in_tls = > | tls_client | {
1947+ try tls_client .writeAll (header );
19581948 if (body ) | b | {
1959- try self .writeAll (b );
1949+ try tls_client .writeAll (b );
19601950 }
19611951 },
19621952 .plain = > | socket | {
@@ -2156,7 +2146,7 @@ const Reader = struct {
21562146 if (result .done == false ) {
21572147 // CONNECT responses should not have a body. If the header is
21582148 // done, then the entire response should be done.
2159- log .err (.http_client , "InvalidConnectResponse" , .{ .unprocessed = result .unprocessed .? });
2149+ log .info (.http_client , "InvalidConnectResponse" , .{ .status = self . response . status , . unprocessed = result .unprocessed });
21602150 return error .InvalidConnectResponse ;
21612151 }
21622152
0 commit comments