Skip to content
CryoCryo home
Stdlibnet

https

import std::net::https; · source

HttpsClient

type struct HttpsClient {
    connector: TlsConnector;

    static new() -> Result<HttpsClient, IoError>;
    static insecure() -> Result<HttpsClient, IoError>;
    async get(&this, host: Str, port: u16, path: Str) -> Result<Response, IoError>;
    async post(&this, host: Str, port: u16, path: Str, content_type: Str, body: Array<u8>) -> Result<Response, IoError>;
    async send(&this, host: Str, port: u16, req: Request) -> Result<Response, IoError>;
    drop(mut &this) -> void;
}

One-shot HTTPS requests. net::https ties the pieces together: resolve the hostname through net::dns (on the blocking pool), dial with TcpConnect, wrap and verify with net::tls, and serialize and parse with net::http. The HTTP layer never learns it is talking to TLS.

import std::net::https;

mut client: HttpsClient = HttpsClient::new()?;
const resp: Response = await client.get(Str::new("example.com"), 443, Str::new("/"))?;

new() verifies certificates against the system store; insecure() does not, and is named accordingly. get and post build the request for you; send takes one you built yourself. The hostname goes into both the TLS SNI extension and the Host header. Each call opens a fresh connection and closes it afterwards — there is no pooling.

Requires ssl and crypto in link_libs, as any use of net::tls does.