std.net.http.client.websocket
Functions
connect
pub fn connect(uri: string | Uri, headers: Headers | <string, string>? = nil, no_proxy: bool = false, proxy: Proxy? = nil, sub_protocols: [string]? = nil): Websocket throws InvalidUriError, WebsocketError, IoError
[src]
pub fn connect(
uri: string | Uri,
headers: (Headers | <string, string>)? = nil,
no_proxy: bool = false,
proxy: Proxy? = nil,
sub_protocols: [string]? = nil
): Websocket throws InvalidUriError, WebsocketError, IoError {
let uri_: Uri;
let conn: Connection;
switch (let uri = uri.(type)) {
case string:
uri_ = try Uri.parse(uri);
case Uri:
uri_ = uri;
}
let host = try uri_.host().ok_or_else(missing_host_error);
let port: int;
if (uri_.scheme() == "wss") {
port = uri_.port() || 443;
} else if (uri_.scheme() == "ws") {
port = uri_.port() || 80;
} else {
throw unsupported_scheme_error();
}
let headers_: Headers? = nil;
if (let headers = headers) {
switch (let headers = headers.(type)) {
case Headers:
headers_ = headers;
case <string, string>:
headers_ = Headers.from_map(headers);
}
}
if (proxy.is_nil() && !no_proxy) {
proxy = Proxy.system();
}
if (let proxy_scheme = proxy.and_then(|proxy| proxy.intercept(uri_))) {
conn = try ProxyConnection.connect(proxy_scheme, host, port);
} else {
conn = try TcpConnection.connect(`${host}:${port}`);
}
if (uri_.scheme() == "wss") {
conn = try TlsConnection.connect(conn, host);
}
let headers_ = headers_ || Headers.new();
return try _Websocket
.connect(_create_native_readwriteclose(conn), uri_, headers_ as _Headers, sub_protocols) as Websocket;
}
connect
pub fn connect(uri: string | Uri, headers: Headers | <string, string>? = nil, no_proxy: bool = false, proxy: Proxy? = nil, sub_protocols: [string]? = nil): Websocket throws InvalidUriError, WebsocketError, IoError
[src]
pub fn connect(
uri: string | Uri,
headers: (Headers | <string, string>)? = nil,
no_proxy: bool = false,
proxy: Proxy? = nil,
sub_protocols: [string]? = nil
): Websocket throws InvalidUriError, WebsocketError, IoError {
let uri_: Uri;
let conn: Connection;
switch (let uri = uri.(type)) {
case string:
uri_ = try Uri.parse(uri);
case Uri:
uri_ = uri;
}
let host = try uri_.host().ok_or_else(missing_host_error);
let port: int;
if (uri_.scheme() == "wss") {
port = uri_.port() || 443;
} else if (uri_.scheme() == "ws") {
port = uri_.port() || 80;
} else {
throw unsupported_scheme_error();
}
let headers_: Headers? = nil;
if (let headers = headers) {
switch (let headers = headers.(type)) {
case Headers:
headers_ = headers;
case <string, string>:
headers_ = Headers.from_map(headers);
}
}
if (proxy.is_nil() && !no_proxy) {
proxy = Proxy.system();
}
if (let proxy_scheme = proxy.and_then(|proxy| proxy.intercept(uri_))) {
conn = try ProxyConnection.connect(proxy_scheme, host, port);
} else {
conn = try TcpConnection.connect(`${host}:${port}`);
}
if (uri_.scheme() == "wss") {
conn = try TlsConnection.connect(conn, host);
}
let headers_ = headers_ || Headers.new();
return try _Websocket
.connect(_create_native_readwriteclose(conn), uri_, headers_ as _Headers, sub_protocols) as Websocket;
}