tiny.http.ClientOperation
Defined in tiny.http.
API (4)
Actions
Public operations.
prepare: Parsesurland writes its host intoscratch.hostand its target intoscratch.targetwithout allocating, so the returned views are slices of those two buffers.validatePlainwriteRequestwriteReusableRequest
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;Complete caller list for ClientOperation.prepare
8 direct callers.
lib.http.src.client.operation.model.test_Client_operation_accepts_exact_host_and_target_capacities[function] — test source atlib/http/src/client/operation/model.zig:373in nearest public ownerlib.http.src.client.operation.modellib.http.src.client.operation.model.test_Client_operation_normalizes_encoded_URL_components_into_caller_storage[function] — test source atlib/http/src/client/operation/model.zig:411in nearest public ownerlib.http.src.client.operation.modellib.http.src.client.operation.model.test_Client_operation_reports_host_target_and_plain_window_exhaustion[function] — test source atlib/http/src/client/operation/model.zig:442in nearest public ownerlib.http.src.client.operation.modellib.http.src.client.operation.model.test_Client_operation_supplies_slash_for_empty_request_target[function] — test source atlib/http/src/client/operation/model.zig:430in nearest public ownerlib.http.src.client.operation.modellib.http.src.client.operation.storage.test_Client_operation_remains_allocation-free_after_storage_seals[function] — test source atlib/http/src/client/operation/storage.zig:260in nearest public ownerlib.http.src.client.operation.storagetiny.http.Client.openWebSocket[method] atlib/http/src/client/runtime.zig:213tiny.http.Client.request[method] atlib/http/src/client/runtime.zig:157tiny.http.Client.requestStream[method] atlib/http/src/client/runtime.zig:267
Audit
| Definitions | 5 |
|---|---|
| Public names | 5 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |