Function connect [src]

Connect to host:port using the specified protocol. This will reuse a connection if one is already open. If a proxy is configured for the client, then the proxy will be used to connect to the host. This function is threadsafe.

Prototype

pub fn connect( client: *Client, host: []const u8, port: u16, protocol: Connection.Protocol, ) ConnectError!*Connection

Parameters

client: *Clienthost: []const u8port: u16protocol: Connection.Protocol

Possible Errors

CertificateBundleLoadFailure RequestError
ConnectionRefused ConnectTcpError
ConnectionResetByPeer ConnectTcpError
ConnectionTimedOut ConnectTcpError
HostLacksNetworkAddresses ConnectTcpError
InvalidCharacter ParseIntError

The input was empty or contained an invalid character

InvalidContentLength SendError
NameServerFailure ConnectTcpError
NetworkUnreachable ConnectTcpError
OutOfMemory Error
Overflow ParseIntError

The result cannot fit in the type specified

TemporaryNameServerFailure ConnectTcpError
TlsInitializationFailed ConnectTcpError
UnexpectedConnectFailure ConnectTcpError
UnexpectedWriteFailure WriteError
UnknownHostName ConnectTcpError
UnsupportedTransferEncoding SendError
UnsupportedUriScheme ConnectErrorPartial
UriMissingHost RequestError

Source

pub fn connect( client: *Client, host: []const u8, port: u16, protocol: Connection.Protocol, ) ConnectError!*Connection { const proxy = switch (protocol) { .plain => client.http_proxy, .tls => client.https_proxy, } orelse return client.connectTcp(host, port, protocol); // Prevent proxying through itself. if (std.ascii.eqlIgnoreCase(proxy.host, host) and proxy.port == port and proxy.protocol == protocol) { return client.connectTcp(host, port, protocol); } if (proxy.supports_connect) tunnel: { return connectTunnel(client, proxy, host, port) catch |err| switch (err) { error.TunnelNotSupported => break :tunnel, else => |e| return e, }; } // fall back to using the proxy as a normal http proxy const conn = try client.connectTcp(proxy.host, proxy.port, proxy.protocol); errdefer { conn.closing = true; client.connection_pool.release(conn); } conn.proxied = true; return conn; }