tiny.http.RequestStorage
Defined in tiny.http.
API (12)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/http/src/message.zig:106
zig
pub const RequestStorage = struct { phase: alloc_phase.capacity.Phase, capacity: RequestStorageCapacity, bytes: []align(@alignOf(RequestHeader)) u8, pub const Limits: type = RequestStorageLimits; pub const Capacity: type = RequestStorageCapacity; pub const Exhaustion: type = RequestStorageExhaustion; pub const InitError = std.mem.Allocator.Error || error{CapacityOverflow}; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "http.request_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "fixed_parsed_header_entry_region_for_every_request_slot", .lifetime = .steady, .detail = "fixed parsed-header entry region for every request slot", }, .{ .id = "fixed_decoded_chunked_body_byte_region_for_every_request_slot", .lifetime = .steady, .detail = "fixed decoded chunked-body byte region for every request slot", }, }, .excluded = &.{ "connection wire input and borrowed content-length bodies", "response output, handlers, clients, TLS, sockets, and kernel queues", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "request_count", "request_count"), alloc_phase.capacity.bindInput(Limits, "header_count_per_request", "header_count_per_request"), alloc_phase.capacity.bindInput(Limits, "body_bytes_per_request", "body_bytes_per_request"), }, .type_selectors = &.{ alloc_phase.capacity.bindType(RequestHeader, "requestheader"), }, .nodes = &.{ .{ .input = 0 }, .{ .input = 1 }, .{ .product = .{ .left = 0, .right = 1 } }, .{ .constant = 1 }, .{ .scale = .{ .node = 3, .coefficient = .{ .size_of_concrete_type = 0 } } }, .{ .product = .{ .left = 2, .right = 4 } }, .{ .input = 2 }, .{ .product = .{ .left = 0, .right = 6 } }, .{ .add = .{ .left = 5, .right = 7 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 8, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "header, line, and body surveys reject max plus one before populating request storage", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "request and chunk surveys allocate no storage after activation", }, .foreign = .{ .status = .excluded, .detail = "request parsing transforms caller-owned memory without I/O", }, }, .obligations = &.{ .{ .key = "http_request_capacity", .role = .capacity_model }, .{ .key = "http_request_oom_retry", .role = .custom }, .{ .key = "http_request_partition", .role = .custom }, .{ .key = "http_request_sealed", .role = .transitive_risk }, .{ .key = "http_request_atomic_overload", .role = .overload }, .{ .key = "http_request_atomic_foreign_risk", .role = .foreign_risk }, .{ .key = "http_request_boundary", .role = .custom }, .{ .key = "http_request_pipeline", .role = .custom }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; pub fn init( allocator: std.mem.Allocator, limits: RequestStorageLimits, ) InitError!RequestStorage { const capacity = try RequestStorageCapacity.derive(limits); const bytes = if (capacity.storage_bytes == 0) @as([]align(@alignOf(RequestHeader)) u8, &.{}) else try allocator.alignedAlloc( u8, .of(RequestHeader), capacity.storage_bytes, ); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, }; } pub fn activate(self: *RequestStorage) void { std.debug.assert(self.phase == .initialization); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .steady; } pub fn request(self: *RequestStorage, index: usize) Exhaustion!RequestScratch { std.debug.assert(self.phase == .steady); if (index >= self.capacity.request_count) return error.RequestCapacityExceeded; const all_headers = std.mem.bytesAsSlice( RequestHeader, self.bytes[0..self.capacity.header_bytes], ); const header_start = index * self.capacity.header_count_per_request; const body_start = self.capacity.header_bytes + index * self.capacity.body_bytes_per_request; return .{ .headers = all_headers[header_start..][0..self.capacity.header_count_per_request], .body = self.bytes[body_start..][0..self.capacity.body_bytes_per_request], .header_line_bytes = self.capacity.header_line_bytes, }; } pub fn deinit(self: *RequestStorage, allocator: std.mem.Allocator) void { std.debug.assert(self.phase != .teardown); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .teardown; if (self.bytes.len != 0) allocator.free(self.bytes); self.bytes = &.{}; }};Source: lib/http/src/root.zig:42
zig
pub const RequestStorage = message.RequestStorage;Complete caller list for RequestStorage.deinit
8 direct callers.
lib.http.src.message.TestParsedRequest.deinit[method] — private source atlib/http/src/message.zig:591in nearest public ownerlib.http.src.messagelib.http.src.message.TestParsedRequest.init[function] — private source atlib/http/src/message.zig:578in nearest public ownerlib.http.src.messagelib.http.src.message.checkRequestStorageInitFailures[function] — private source atlib/http/src/message.zig:675in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_capacity_failures_preserve_header_and_body_storage[function] — test source atlib/http/src/message.zig:753in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_content-length_body_borrows_input_and_preserves_decoded_storage[function] — test source atlib/http/src/message.zig:847in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_parser_accepts_exact_limits_and_rejects_max_plus_one[function] — test source atlib/http/src/message.zig:801in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_parsing_remains_allocation-free_after_storage_seals[function] — test source atlib/http/src/message.zig:867in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_storage_partitions_reusable_slots[function] — test source atlib/http/src/message.zig:705in nearest public ownerlib.http.src.message
Complete caller list for RequestStorage.init
7 direct callers.
lib.http.src.message.TestParsedRequest.init[function] — private source atlib/http/src/message.zig:578in nearest public ownerlib.http.src.messagelib.http.src.message.checkRequestStorageInitFailures[function] — private source atlib/http/src/message.zig:675in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_capacity_failures_preserve_header_and_body_storage[function] — test source atlib/http/src/message.zig:753in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_content-length_body_borrows_input_and_preserves_decoded_storage[function] — test source atlib/http/src/message.zig:847in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_parser_accepts_exact_limits_and_rejects_max_plus_one[function] — test source atlib/http/src/message.zig:801in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_parsing_remains_allocation-free_after_storage_seals[function] — test source atlib/http/src/message.zig:867in nearest public ownerlib.http.src.messagelib.http.src.message.test_Request_storage_partitions_reusable_slots[function] — test source atlib/http/src/message.zig:705in nearest public ownerlib.http.src.message
Audit
| Definitions | 10 |
|---|---|
| Public names | 10 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |