Skip to content
CryoCryo home
Stdlibnet

https

import std::net::https; · source

Types

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>;
}

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.

Properties

PropertyType
connectorTlsConnector

Constructors

static new() -> Result<HttpsClient, IoError>;

New client with full certificate + hostname verification against the system trust store.

static insecure() -> Result<HttpsClient, IoError>;

New client that skips certificate verification. For self-signed or out-of-band-pinned servers only - never for the open web.

Methods

async get(&this, host: Str, port: u16, path: Str) -> Result<Response, IoError>;

GET https://host:port/path. Resolves host, dials, performs the TLS handshake with SNI = host, then sends the request and reads one response.

async post(&this, host: Str, port: u16, path: Str, content_type: Str, body: Array<u8>) -> Result<Response, IoError>;

POST https://host:port/path with a body. Sets Host and the given Content-Type; the request's Content-Length is set by set_body.

async send(&this, host: Str, port: u16, req: Request) -> Result<Response, IoError>;

Resolve, dial, wrap in TLS, and run one request/response.