Skip to documentation
SLOP

tiny.http.ClientOperation

Reference tiny.http ClientOperation

Defined in tiny.http.

API (4)

Actions

Public operations.

No direct callersNo direct callstiny.httpClientOperation
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/http/src/client/operation/model.zig:109

zig
pub const ClientOperation = struct {    /// Parses `url` and writes its host into `scratch.host` and its target into    /// `scratch.target` without allocating, so the returned views are slices of    /// those two buffers. The port comes from the URL, or from the scheme when the    /// URL omits it: 443 for https and 80 for http. A scheme other than http or    /// https returns `error.UnsupportedScheme` , and a URL with no host returns    /// `error.MissingHost` . A host or target longer than its buffer returns a    /// capacity error and writes no prepared operation, so a caller can enlarge    /// that buffer and call again.    pub fn prepare(scratch: Scratch, url: []const u8) Error!Prepared {        const uri = std.Uri.parse(url) catch return error.InvalidUrl;        const is_http = std.ascii.eqlIgnoreCase(uri.scheme, "http");        const is_https = std.ascii.eqlIgnoreCase(uri.scheme, "https");        if (!is_http and !is_https) return error.UnsupportedScheme;        const host_component = uri.host orelse return error.MissingHost;        const host = try componentInto(            host_component,            scratch.host,            error.ClientHostCapacityExceeded,        );        const target = try targetInto(uri, scratch.target);        std.debug.assert(host.len <= scratch.host.len);        std.debug.assert(target.len <= scratch.target.len);        std.debug.assert(host.ptr == scratch.host.ptr);        std.debug.assert(target.ptr == scratch.target.ptr);        const default_port: u16 = if (is_https) 443 else 80;        return .{            .host = host,            .target = target,            .port = uri.port orelse default_port,            .is_tls = is_https,        };    }    pub fn validatePlain(scratch: Scratch) Error!void {        if (scratch.plain_read.len == 0) {            return error.ClientPlainReadCapacityExceeded;        }        if (scratch.plain_write.len == 0) {            return error.ClientPlainWriteCapacityExceeded;        }        std.debug.assert(scratch.plain_read.len > 0);        std.debug.assert(scratch.plain_write.len > 0);    }    pub fn writeRequest(        writer: *std.Io.Writer,        method: []const u8,        host: []const u8,        target: []const u8,        headers: []const response.Header,        body: []const u8,    ) std.Io.Writer.Error!void {        return writeRequestConnection(            writer,            method,            host,            target,            headers,            body,            "close",        );    }    pub fn writeReusableRequest(        writer: *std.Io.Writer,        method: []const u8,        host: []const u8,        target: []const u8,        headers: []const response.Header,        body: []const u8,    ) std.Io.Writer.Error!void {        return writeRequestConnection(            writer,            method,            host,            target,            headers,            body,            "keep-alive",        );    }    fn writeRequestConnection(        writer: *std.Io.Writer,        method: []const u8,        host: []const u8,        target: []const u8,        headers: []const response.Header,        body: []const u8,        connection: []const u8,    ) std.Io.Writer.Error!void {        std.debug.assert(method.len > 0);        std.debug.assert(host.len > 0);        std.debug.assert(target.len > 0);        std.debug.assert(connection.len > 0);        try writer.writeAll(method);        try writer.writeByte(' ');        try writer.writeAll(target);        try writer.writeAll(" HTTP/1.1\r\nHost: ");        try writer.writeAll(host);        try writer.writeAll("\r\n");        for (headers) |header| {            try writer.writeAll(header.name);            try writer.writeAll(": ");            try writer.writeAll(header.value);            try writer.writeAll("\r\n");        }        try writer.print("Content-Length: {d}\r\n", .{body.len});        try writer.writeAll("Connection: ");        try writer.writeAll(connection);        try writer.writeAll("\r\n\r\n");        try writer.writeAll(body);    }};

Source: lib/http/src/root.zig:84

zig
pub const ClientOperation = client.ClientOperation;
Called byCallstest sourcelib.http.src.client.operation.modeltest: Client operation accepts exact ...test sourcelib.http.src.client.operation.modeltest: Client operation normalizes enc...test sourcelib.http.src.client.operation.modeltest: Client operation reports host t...test sourcelib.http.src.client.operation.modeltest: Client operation supplies slash...test sourcelib.http.src.client.operation.storagetest: Client operation remains alloca...+3 moreprivate sourcelib.http.src.client.operation.modelcomponentIntoprivate sourcelib.http.src.client.operation.modeltargetIntoClientOperationprepare
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.http.src.client.operation.modeltest: Client operation accepts exact ...test sourcelib.http.src.client.operation.modeltest: Client operation reports host t...ClientopenWebSocketClientrequestClientrequestStreamClientOperationvalidatePlain
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.http.src.client.operation.modeltest: Client operation serializes req...test sourcelib.http.src.client.operation.storagetest: Client operation remains alloca...private sourcelib.http.src.client.runtime.ClientdoPlainRequestprivate sourcelib.http.src.client.runtime.ClientdoPlainRequestStreamprivate sourcelib.http.src.client.runtime.ClientdoTlsRequestprivate sourcelib.http.src.client.runtime.ClientdoTlsRequestStreamprivate sourcelib.http.src.client.operation.model.ClientOpe...writeRequestConnectionClientOperationwriteRequest
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.http.src.client.operation.modeltest: Client reusable operation reque...private sourcelib.http.src.client.runtime.ClientperformReusableRequestprivate sourcelib.http.src.client.operation.model.ClientOpe...writeRequestConnectionClientOperationwriteReusableRequest
Static calls · unresolved targets: 0 · external targets: 0.

Complete caller list for ClientOperation.prepare

8 direct callers.

Audit

Definitions5
Public names5
Members0
Version26.7.0
Revisiondaab053ee433