connectTcpOptions
Function parameters
Parameters
- client:*Client
A Least-Recently-Used cache of open connections to be reused.
Types
- ConnectionPool
- A Least-Recently-Used cache of open connections to be reused.
Release all associated resources with the client.
Functions
- deinit
- Release all associated resources with the client.
- initDefaultProxies
- Populates `http_proxy` and `https_proxy` via standard proxy environment variables.
- connectTcp
- Reuses a `Connection` if one matching `host` and `port` is already open.
- connectUnix
- Connect to `path` as a unix domain socket.
- connectProxied
- Connect to `proxied_host:proxied_port` using the specified proxy with HTTP
- connect
- Connect to `host:port` using the specified protocol.
- request
- Open a connection to the host specified by `uri` and prepare to send a HTTP request.
- fetch
- Perform a one-shot HTTP request with the provided options.
Error sets in this namespace
Error Sets
= std.options.http_disable_tls
Values
- disable_tls
- = std.options.http_disable_tls
Source
Implementation
pub fn connectTcpOptions(client: *Client, options: ConnectTcpOptions) ConnectTcpError!*Connection {
const host = options.host;
const port = options.port;
const protocol = options.protocol;
const proxied_host = options.proxied_host orelse host;
const proxied_port = options.proxied_port orelse port;
if (client.connection_pool.findConnection(.{
.host = proxied_host,
.port = proxied_port,
.protocol = protocol,
})) |conn| return conn;
const stream = net.tcpConnectToHost(client.allocator, host, port) catch |err| switch (err) {
error.ConnectionRefused => return error.ConnectionRefused,
error.NetworkUnreachable => return error.NetworkUnreachable,
error.ConnectionTimedOut => return error.ConnectionTimedOut,
error.ConnectionResetByPeer => return error.ConnectionResetByPeer,
error.TemporaryNameServerFailure => return error.TemporaryNameServerFailure,
error.NameServerFailure => return error.NameServerFailure,
error.UnknownHostName => return error.UnknownHostName,
error.HostLacksNetworkAddresses => return error.HostLacksNetworkAddresses,
else => return error.UnexpectedConnectFailure,
};
errdefer stream.close();
switch (protocol) {
.tls => {
if (disable_tls) return error.TlsInitializationFailed;
const tc = try Connection.Tls.create(client, proxied_host, proxied_port, stream);
client.connection_pool.addUsed(&tc.connection);
return &tc.connection;
},
.plain => {
const pc = try Connection.Plain.create(client, proxied_host, proxied_port, stream);
client.connection_pool.addUsed(&pc.connection);
return &pc.connection;
},
}
}