DefaultHttpConnector
struct DefaultHttpConnector
A default HTTP connector.
Implementions
Methods
new
pub fn new(no_proxy: bool = false, proxy: Proxy? = nil): DefaultHttpConnector
[src]
pub fn new(no_proxy: bool = false, proxy: Proxy? = nil): DefaultHttpConnector {
if (proxy.is_nil() && !no_proxy) {
proxy = Proxy.system();
}
return DefaultHttpConnector { proxy };
}
Creates a new default HTTP connector.
new
pub fn new(no_proxy: bool = false, proxy: Proxy? = nil): DefaultHttpConnector
[src]
pub fn new(no_proxy: bool = false, proxy: Proxy? = nil): DefaultHttpConnector {
if (proxy.is_nil() && !no_proxy) {
proxy = Proxy.system();
}
return DefaultHttpConnector { proxy };
}
Creates a new default HTTP connector.
Creates a new default HTTP connector.
connect
pub fn connect(self, uri: Uri): HttpConnection throws IoError
[src]
pub fn connect(self, uri: Uri): HttpConnection throws IoError {
let conn: Connection;
let is_negotiated_h2 = false;
let host = try uri.host().ok_or_else(|| IoError.other("missing host in url"));
let port: int;
if (uri.scheme() == "https") {
port = uri.port() || 443;
} else if (uri.scheme() == "http") {
port = uri.port() || 80;
} else {
throw IoError.other("unsupported scheme");
}
if (let proxy_scheme = self.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() == "https") {
let tls_conn = try TlsConnection.connect(conn, host, alpn_protocols: ["h2", "http/1.1"]);
is_negotiated_h2 = tls_conn.alpn_protocol() == "h2";
conn = tls_conn;
}
return DefaultHttpConnection { conn, is_negotiated_h2 };
}
connect
pub fn connect(self, uri: Uri): HttpConnection throws IoError
[src]
pub fn connect(self, uri: Uri): HttpConnection throws IoError {
let conn: Connection;
let is_negotiated_h2 = false;
let host = try uri.host().ok_or_else(|| IoError.other("missing host in url"));
let port: int;
if (uri.scheme() == "https") {
port = uri.port() || 443;
} else if (uri.scheme() == "http") {
port = uri.port() || 80;
} else {
throw IoError.other("unsupported scheme");
}
if (let proxy_scheme = self.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() == "https") {
let tls_conn = try TlsConnection.connect(conn, host, alpn_protocols: ["h2", "http/1.1"]);
is_negotiated_h2 = tls_conn.alpn_protocol() == "h2";
conn = tls_conn;
}
return DefaultHttpConnection { conn, is_negotiated_h2 };
}