silk/http_content
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Bounded scoped HTTP response content decoding over strict body framing.
When to use
Build a ResponseContext from one validated response head, request method, and trailer
policy, consume it into a CodingPlan, then use withReader to stream either the raw
representation or a validated reverse content-decoding stack.
Details
Planning parses at most four content codings and performs every configuration and owned-memory
check before codec acquisition or body I/O. Readers exclusively borrow an existing
BufferedDuplex for one callback. Bytes returned before ContentCompletion are
provisional because a later wrapper checksum, trailer, or framed boundary can still fail.
Gotchas
This low-level actor treats the body supplied to each withReader invocation as the encoded
representation described by the plan. It does not prove that those bytes came from the retained
head and cannot prevent a copied head from being planned over already-decoded bytes. The affine
response/body envelope in silk.http_client owns that stronger provenance and decode-once contract.
Cleanup is guaranteed for structured Effect exits, including interruption, but not for fatal
traps that bypass Effect finalizers and Drop.
Import as ContentReader with import silk.http_content { ContentReader }.
Public declarations: 25.
Mode
pub enum ModeWhether the representation is preserved or decoded.
Raw
Raw = 0Preserves encoded representation bytes without interpreting Content-Encoding.
Decode
Decode = 1Validates Content-Encoding and applies the supported reverse decoding stack.
Coding
pub enum CodingOne recognized response content coding.
Identity
Identity = 0Leaves representation bytes unchanged and counts toward the coding depth.
Gzip
Gzip = 1Decodes gzip members, including permitted concatenated members.
XGzip
XGzip = 2Accepts the legacy response spelling of gzip with the same decoding rules.
Deflate
Deflate = 3Decodes one zlib-wrapped stream; raw DEFLATE and trailing bytes fail.
Zstd
Zstd = 4Decodes Zstandard frames under the configured window and workspace limits.
CodingPosition
pub struct CodingPositionThe exact source coordinates of one coding token.
Field wireIndex
pub wireIndex: usizeThe zero-based coding position across all Content-Encoding fields.
Field fieldIndex
pub fieldIndex: usizeThe zero-based header field position in the original response.
Field elementIndex
pub elementIndex: usizeThe zero-based comma element within its Content-Encoding field.
Field offset
pub offset: usizeThe byte offset of the coding token or invalid byte within the field value.
Implementation Copy for CodingPosition
impl Copy for CodingPositionLimits
pub struct LimitsThe finite content, composition, and codec allowances copied into a plan.
Field maxEncoded
pub maxEncoded: u64The maximum representation bytes accepted after HTTP deframing.
Field maxIntermediate
pub maxIntermediate: u64The maximum combined bytes produced by all nonfinal codec stages.
Field maxDecoded
pub maxDecoded: u64The maximum final representation bytes returned to the caller.
Field maxOwned
pub maxOwned: usizeThe maximum admitted composition and codec storage reservation, excluding body-decoder storage.
Field maxDepth
pub maxDepth: usizeThe maximum coding entries, including identity; must be between one and four.
Field intermediateCapacity
pub intermediateCapacity: usizeThe capacity of each active stage edge; must be between one and 65,536 bytes.
Field inflate
pub inflate: InflateLimitsThe limits applied independently to each gzip or zlib decoder.
Field zstd
pub zstd: ZstdLimitsThe limits applied independently to each Zstandard decoder.
ContentLimitKind
pub enum ContentLimitKindThe configuration or byte class rejected by the content layer.
CodingDepth
CodingDepth = 0The permitted number of content-coding entries.
IntermediateCapacity
IntermediateCapacity = 1The finite capacity of one stage edge.
OwnedBytes
OwnedBytes = 2The admitted composition and codec storage reservation.
EncodedBytes
EncodedBytes = 3The deframed representation input byte allowance.
IntermediateBytes
IntermediateBytes = 4The combined output allowance for nonfinal decoding stages.
DecodedBytes
DecodedBytes = 5The final representation output byte allowance.
ContentReason
pub union ContentReason<'head>A stage-aware content, framing, transport, or codec failure.
InvalidLimit
ContentReason<'head>.InvalidLimit { limit: ContentLimitKind, allowed: u64, attempted: u64 }: ContentReason<'head>A configuration or byte count exceeds its permitted range.
Field limit
pub limit: ContentLimitKindThe rejected configuration or byte class.
Field allowed
pub allowed: u64The applicable maximum.
Field attempted
pub attempted: u64The rejected value or count.
CodingSyntax
ContentReason<'head>.CodingSyntax { position: CodingPosition }: ContentReason<'head>A Content-Encoding element is empty or contains invalid syntax.
Field position
pub position: CodingPositionThe exact location of the invalid token or byte.
UnsupportedCoding
ContentReason<'head>.UnsupportedCoding { position: CodingPosition, token: &'head [u8] }: ContentReason<'head>A valid coding token names an unsupported decoder.
Field position
pub position: CodingPositionThe token position in the original response.
Field token
pub token: &'head [u8]The untouched unsupported token borrowed from the response.
PartialResponse
ContentReason<'head>.PartialResponse { position: CodingPosition }: ContentReason<'head>A 206 response selects a nonidentity coding in Decode mode.
Field position
pub position: CodingPositionThe first nonidentity coding in wire order.
Tunnel
ContentReason<'head>.Tunnel: ContentReason<'head>The selected body is a protocol tunnel rather than an HTTP representation.
Body
ContentReason<'head>.Body { error: BodyError }: ContentReason<'head>HTTP body framing failed before content completion.
Field error
pub error: BodyErrorThe original body error, including committed wire progress.
Buffer
ContentReason<'head>.Buffer { error: BufferError }: ContentReason<'head>The buffered transport failed.
Field error
pub error: BufferErrorThe original buffer error and its transport cause.
Inflate
ContentReason<'head>.Inflate { stage: usize, wireIndex: usize, error: DecodeError }: ContentReason<'head>A gzip or zlib decoder rejected configuration or input.
Field stage
pub stage: usizeThe zero-based reverse application stage.
Field wireIndex
pub wireIndex: usizeThe original coding position in wire order.
Field error
pub error: DecodeErrorThe exact inflate failure and decoder-call progress.
Zstandard
ContentReason<'head>.Zstandard { stage: usize, wireIndex: usize, error: ZstdError }: ContentReason<'head>A Zstandard decoder rejected configuration or input.
Field stage
pub stage: usizeThe zero-based reverse application stage.
Field wireIndex
pub wireIndex: usizeThe original coding position in wire order.
Field error
pub error: ZstdErrorThe exact Zstandard failure and decoder-call progress.
TrailingEncodedData
ContentReason<'head>.TrailingEncodedData { stage: usize, wireIndex: usize }: ContentReason<'head>A finished coding stream has additional encoded bytes.
Field stage
pub stage: usizeThe zero-based reverse application stage.
Field wireIndex
pub wireIndex: usizeThe original coding position in wire order.
ArithmeticOverflow
ContentReason<'head>.ArithmeticOverflow: ContentReason<'head>A checked byte or reservation calculation cannot represent its result.
InvalidState
ContentReason<'head>.InvalidState: ContentReason<'head>The reader previously failed or was abandoned.
ContentError
pub struct ContentError<'head>Exact per-call and cumulative coordinates for a content failure.
Field reason
pub reason: silk/http_content.ContentReason<'head>The exact failure category and its lower-level cause when available.
Field written
pub written: usizeThe representation bytes written to the caller destination during this read.
Field totalEncoded
pub totalEncoded: u64The cumulative representation bytes accepted after HTTP deframing.
Field totalIntermediate
pub totalIntermediate: u64The cumulative output bytes accepted from all nonfinal codec stages.
Field totalDecoded
pub totalDecoded: u64The cumulative representation bytes written to caller destinations.
ContentProgressState
pub enum ContentProgressStateWhether one successful read returned data or established terminal completion.
Data
Data = 0Reports provisional output or internal progress before complete validation.
End
End = 1Reports successful completion of the framed body and all content stages.
ContentProgress
pub struct ContentProgressExact per-call and cumulative committed content progress.
Field written
pub written: usizeThe representation bytes written to the caller destination during this read.
Field totalEncoded
pub totalEncoded: u64The cumulative representation bytes accepted after HTTP deframing.
Field totalIntermediate
pub totalIntermediate: u64The cumulative output bytes accepted from all nonfinal codec stages.
Field totalDecoded
pub totalDecoded: u64The cumulative representation bytes written to caller destinations.
Field state
pub state: ContentProgressStateWhether content remains provisional or has completed validation.
ReuseDisposition
pub enum ReuseDispositionConnection reuse policy before and after positive completion evidence.
EligibleAfterCompletion
EligibleAfterCompletion = 0Allows reuse only after successful content completion supplies positive evidence.
Reusable
Reusable = 1Confirms delimited framing, no framing anomaly, and successful content completion.
NonReusable
NonReusable = 2Forbids reuse because framing closes the connection or carries an anomaly.
AppliedPlan
pub struct AppliedPlanPublic applied-plan metadata without exposing the affine plan itself.
Field mode
pub mode: ModeWhether the plan preserves or decodes the representation.
Field codingCount
pub codingCount: usizeThe number of parsed coding entries, including identity.
Field decoderCount
pub decoderCount: usizeThe number of active nonidentity codec stages.
Field reuse
pub reuse: ReuseDispositionThe reuse disposition established by the plan or completion.
Implementation Copy for AppliedPlan
impl Copy for AppliedPlanRepresentationView
pub struct RepresentationView<'owner, 'head>Borrowed effective representation metadata that never rewrites wire headers.
Method RepresentationView.originalHead
pub fn originalHead<'owner, 'head, 'life2>(self: &'life2 RepresentationView<'owner, 'head>) -> silk/http_head.ResponseHead<'head>Returns the untouched response head with its original coding and length headers.
Method RepresentationView.appliedPlan
pub fn appliedPlan<'owner, 'head, 'life2>(self: &'life2 RepresentationView<'owner, 'head>) -> AppliedPlanReturns the effective coding counts, mode, and reuse disposition.
Method RepresentationView.anomaly
pub fn anomaly<'owner, 'head, 'life2>(self: &'life2 RepresentationView<'owner, 'head>) -> AnomalyReturns the exact framing anomaly selected from the original response.
Method RepresentationView.decodingApplied
pub fn decodingApplied<'owner, 'head, 'life2>(self: &'life2 RepresentationView<'owner, 'head>) -> boolReturns whether at least one nonidentity content decoder was selected.
Method RepresentationView.decodedLength
pub fn decodedLength<'owner, 'head, 'life2>(self: &'life2 RepresentationView<'owner, 'head>) -> silk/option.Option<u64>Returns the final decoded length only after completion, or zero for semantic no-body responses.
ContentCompletion
pub struct ContentCompletion<'owner>Opaque positive evidence that framing and every selected codec completed.
Method ContentCompletion.bodyKind
pub fn bodyKind<'owner, 'life1>(self: &'life1 ContentCompletion<'owner>) -> BodyCompletionKindReturns whether the completed body was delimited or ended at transport closure.
Method ContentCompletion.decodedBytes
pub fn decodedBytes<'owner, 'life1>(self: &'life1 ContentCompletion<'owner>) -> u64Returns the final validated representation byte count.
Method ContentCompletion.anomaly
pub fn anomaly<'owner, 'life1>(self: &'life1 ContentCompletion<'owner>) -> AnomalyReturns the exact framing anomaly selected from the original response.
Method ContentCompletion.reuse
pub fn reuse<'owner, 'life1>(self: &'life1 ContentCompletion<'owner>) -> ReuseDispositionReturns the reuse disposition supported by this completed representation.
ResponseContext
pub struct ResponseContext<'head, 'method, 'names>Atomic response-selection provenance. Its fields are intentionally private.
Associated function ResponseContext.make
pub fn make<'head, 'method, 'names>(head: silk/http_head.ResponseHead<'head>, requestMethod: silk/http.Method<'method>, trailerPolicy: silk/http_body.TrailerPolicy<'names>) -> silk/result.Result<silk/http_content.ResponseContext<'head, 'method, 'names>, silk/http_body.BodyError>Selects response framing and constructs no context when selection fails.
CodingPlan
pub struct CodingPlan<'head, 'method, 'names>A validated single-use response plan. Construction consumes its complete context.
Associated function CodingPlan.make
pub fn make<'head, 'method, 'names>(context: silk/http_content.ResponseContext<'head, 'method, 'names>, mode: Mode, bodyLimits: BodyLimits, limits: Limits) -> silk/result.Result<silk/http_content.CodingPlan<'head, 'method, 'names>, silk/http_content.ContentError<'head>>Validates all policy and storage requirements without allocation or body I/O.
Method CodingPlan.originalHead
pub fn originalHead<'head, 'method, 'names, 'life3>(self: &'life3 CodingPlan<'head, 'method, 'names>) -> silk/http_head.ResponseHead<'head>Returns the untouched response head with its original coding and length headers.
Method CodingPlan.selectionAnomaly
pub fn selectionAnomaly<'head, 'method, 'names, 'life3>(self: &'life3 CodingPlan<'head, 'method, 'names>) -> AnomalyReturns the selected framing anomaly exactly.
Method CodingPlan.selectedFraming
pub fn selectedFraming<'head, 'method, 'names, 'life3>(self: &'life3 CodingPlan<'head, 'method, 'names>) -> FramingReturns the framing retained by atomic selection.
Method CodingPlan.applied
pub fn applied<'head, 'method, 'names, 'life3>(self: &'life3 CodingPlan<'head, 'method, 'names>) -> AppliedPlanReturns the effective plan metadata.
Method CodingPlan.ownedBytes
pub fn ownedBytes<'head, 'method, 'names, 'life3>(self: &'life3 CodingPlan<'head, 'method, 'names>) -> usizeReturns the deterministic owned reservation admitted by the plan.
EnabledCodings
pub struct EnabledCodingsEnabled automatic request codings. x-gzip is deliberately absent.
Field gzip
pub gzip: boolEnables gzip in automatic Accept-Encoding output.
Field deflate
pub deflate: boolEnables zlib-wrapped deflate in automatic Accept-Encoding output.
Field zstd
pub zstd: boolEnables zstd in automatic Accept-Encoding output.
Implementation Copy for EnabledCodings
impl Copy for EnabledCodingsEmptyEncodingPolicy
pub enum EmptyEncodingPolicyThe explicit automatic behavior when no decoder is enabled.
Identity
Identity = 0Advertises identity when automatic negotiation enables no codec.
Omit
Omit = 1Omits Accept-Encoding when automatic negotiation enables no codec.
AcceptEncoding
pub union AcceptEncoding<'value>Automatic, exact borrowed override, or omitted Accept-Encoding policy.
Automatic
AcceptEncoding<'value>.Automatic { enabled: EnabledCodings, empty: EmptyEncodingPolicy }: AcceptEncoding<'value>Advertises enabled codecs in stable gzip, deflate, zstd order for Decode mode.
Field enabled
pub enabled: EnabledCodingsThe supported codecs to advertise.
Field empty
pub empty: EmptyEncodingPolicyThe policy when no codec is enabled.
Override
AcceptEncoding<'value>.Override { value: &'value [u8] }: AcceptEncoding<'value>Uses the caller value exactly after shared HTTP header validation.
Field value
pub value: &'value [u8]The borrowed field value; this value does not weaken response decoding validation.
Omit
AcceptEncoding<'value>.Omit: AcceptEncoding<'value>Omits Accept-Encoding without constructing a header.
acceptEncoding
pub fn acceptEncoding<'value>(mode: Mode, policy: silk/http_content.AcceptEncoding<'value>, limits: HeaderLimits) -> silk/result.Result<silk/option.Option<silk/http.Header<'value>>, silk/http.ValueError>Builds at most one validated Accept-Encoding field without mutating a request.
validateLimits
pub fn validateLimits<'head, 'life1>(limits: &'life1 silk/http_content.Limits) -> silk/result.Result<(), silk/http_content.ContentError<'head>>Validates source-independent content limits without allocation or body I/O.
Details
maxDepth must be from one through four. intermediateCapacity must be from one through
65,536 bytes. Other byte limits can be zero and are enforced by planning or content I/O.
Codec-specific storage validation occurs when a plan selects that codec.
Decoder
pub struct DecoderOwned framing and content state for a caller-owned wire transport.
Details
Planning consumes borrowed metadata, but the resulting decoder owns all runtime state. The
caller retains input bytes not consumed by step, including the next HTTP message suffix.
A higher-level response owner must bind the plan and those wire bytes to the same response.
Associated function Decoder.make
pub effect<'env> fn make<'head: 'env, 'method: 'env, 'names: 'env, 'env>(plan: silk/http_content.CodingPlan<'head, 'method, 'names>) -> Decoder ! silk/http_content.ContentError<'head> | OutOfMemoryError ? &mut AllocatorAcquires the existing bounded framing and codec stack from one validated plan.
Method Decoder.step
pub fn step<'life0, 'life1, 'life2>(self: &'life0 mut Decoder, input: &'life1 [u8], output: &'life2 mut [u8], endOfInput: bool) -> silk/result.Result<silk/http_content.DecodeProgress, silk/http_content.DecodeFailure>Advances without I/O, retaining exact consumed and written prefixes on failure.
Details
endOfInput promises no bytes follow the supplied input. Returned representation bytes
remain provisional until completion confirms framing, checksums and pending output.
Empty output completes locally without consuming input or changing a live decoder.
Method Decoder.progress
pub fn progress<'life0>(self: &'life0 Decoder) -> ContentProgressReports the current cumulative representation coordinates without advancing input.
Method Decoder.completion
pub fn completion<'owner>(self: &'owner Decoder) -> silk/result.Result<silk/option.Option<silk/http_content.ContentCompletion<'owner>>, silk/http_content.ContentError<'static>>Borrows successful framing and content completion from this owner.
Method Decoder.trailers
pub fn trailers<'owner>(self: &'owner Decoder) -> silk/result.Result<silk/option.Option<silk/http_body.Trailers<'owner>>, silk/http_content.ContentError<'static>>Borrows trailers only after successful content and body completion.
Method Decoder.abandon
pub fn abandon<'life0>(self: &'life0 mut Decoder) -> ()Permanently abandons unfinished decoding without reading or draining the transport.
DecodeProgress
pub struct DecodeProgressOne incremental wire-to-representation transition.
Field consumed
pub consumed: usizeThe exact wire prefix consumed from the supplied input.
Field progress
pub progress: ContentProgressProvisional output and cumulative representation coordinates.
Field needsInput
pub needsInput: boolWhether another wire prefix is needed before the decoder can advance.
DecodeFailure
pub struct DecodeFailureA content failure with its committed input prefix and owned runtime cause.
Field consumed
pub consumed: usizeThe exact wire prefix consumed before the failure.
Field error
pub error: silk/http_content.ContentError<'static>The original content, framing, or codec failure and output coordinates.
ContentReader
pub struct ContentReader<'reader, 'transport, 'head, P>One callback-scoped exclusive content reader.
Method ContentReader.representation
pub fn representation<'reader, 'transport, 'head, P, 'owner>(self: &'owner ContentReader<'reader, 'transport, 'head, P>) -> silk/result.Result<silk/http_content.RepresentationView<'owner, 'head>, silk/http_content.ContentError<'head>>Borrows untouched wire metadata and the effective applied plan.
Method ContentReader.completion
pub fn completion<'reader, 'transport, 'head, P, 'owner>(self: &'owner ContentReader<'reader, 'transport, 'head, P>) -> silk/result.Result<silk/option.Option<silk/http_content.ContentCompletion<'owner>>, silk/http_content.ContentError<'head>>Returns positive completion only after framing, codecs, and pending output finish.
Method ContentReader.trailers
pub fn trailers<'reader, 'transport, 'head, P, 'owner>(self: &'owner ContentReader<'reader, 'transport, 'head, P>) -> silk/result.Result<silk/option.Option<silk/http_body.Trailers<'owner>>, silk/http_content.ContentError<'head>>Borrows trailers only through successful content and body completion.
Method ContentReader.readSome
pub effect<'env> fn readSome<'reader: 'env, 'transport: 'env, 'head: 'env, P: 'env, 'life4: 'env, 'life5: 'env, 'env>(self: &'life4 mut ContentReader<'reader, 'transport, 'head, P>, output: &'life5 mut [u8], deadline: silk/option.Option<silk/system_clock.Instant>) -> ContentProgress ! silk/http_content.ContentError<'head> ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClockStreams one provisional prefix with one unchanged absolute deadline.
withReader
pub effect<'env> fn withReader<'reader: 'env, 'transport: 'reader + 'env, 'head: 'reader + 'env, 'method: 'reader + 'env, 'names: 'reader + 'env, 'callback: 'env, A, E, ?CallbackRequirements, P: 'env, 'env>(plan: silk/http_content.CodingPlan<'head, 'method, 'names>, body: &'reader mut silk/buffered_duplex.BufferedDuplex<'transport, P>, callback: for<'call, 'readerView: 'call, 'transportView: 'readerView, 'headView: 'readerView> once fn<'callback>(&'call mut silk/http_content.ContentReader<'readerView, 'transportView, 'headView, P>) -> once Effect<'call; A ! E ? CallbackRequirements>) -> A ! E | silk/http_content.ContentError<'head> | OutOfMemoryError ? CallbackRequirements | &mut Allocator where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClockRuns one higher-ranked callback while exclusively borrowing the encoded body.