Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › http › Client › connectProxied Public Function connectProxied Doc Source Public Function std.http.Client.connectProxied
pub fn connectProxied (
client : *Client ,
proxy : *Proxy ,
proxied_host : HostName ,
proxied_port : u16 ,
) !*Connection Params File http/Client.zig: 1526
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589 pub fn connectProxied (
client : *Client ,
proxy : *Proxy ,
proxied_host : HostName ,
proxied_port : u16 ,
) !*Connection {
const io = client .io ;
if (!proxy .supports_connect ) return error .TunnelNotSupported ;
if (try client .connection_pool .findConnection (io , .{
.host = proxied_host ,
.port = proxied_port ,
.protocol = proxy .protocol ,
})) |node | return node ;
var maybe_valid = false ;
(tunnel : {
const connection = try client .connectTcpOptions (.{
.host = proxy .host ,
.port = proxy .port ,
.protocol = proxy .protocol ,
.proxied_host = proxied_host ,
.proxied_port = proxied_port ,
});
errdefer {
connection .closing = true ;
client .connection_pool .release (connection , io );
}
var req = client .request (.CONNECT , .{
.scheme = "http" ,
.host = .{ .raw = proxied_host .bytes },
.port = proxied_port ,
}, .{
.redirect_behavior = .unhandled ,
.connection = connection ,
}) catch |err | {
break :tunnel err ;
};
defer req .deinit ();
req .sendBodiless () catch |err | break :tunnel err ;
const response = req .receiveHead (&.{}) catch |err | break :tunnel err ;
if (response .head .status .class () == .server_error ) {
maybe_valid = true ;
break :tunnel error .ServerError ;
}
if (response .head .status != .ok ) break :tunnel error .ConnectionRefused ;
// this connection is now a tunnel, so we can't use it for anything
// else, it will only be released when the client is de-initialized.
req .connection = null ;
connection .closing = false ;
return connection ;
}) catch {
// something went wrong with the tunnel
proxy .supports_connect = maybe_valid ;
return error .TunnelNotSupported ;
};
}
Connect to
proxied_host:proxied_portusing the specified proxy with HTTP CONNECT. This will reuse a connection if one is already open.This function is threadsafe.