Silk

silk/http_request

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.

Origin-bound HTTP request preparation with finite storage and explicit header policy.

Details

prepare owns the direct serialized head before an exchange can send bytes. The routed operations require a policy-selected proxy route. They derive the proxy peer and authentication from that route. All operations generate framing fields and reject conflicting caller fields.

Import as HttpRequest with import silk.http_request as HttpRequest.

Public declarations: 11.

BodyMode

pub union BodyMode

The exact request payload delimiter.

Empty

BodyMode.Empty: BodyMode

Sends no request payload.

KnownLength

BodyMode.KnownLength { length: u64 }: BodyMode

Sends exactly this many payload bytes.

Field length

pub length: u64

The exact payload length.

Chunked

BodyMode.Chunked: BodyMode

Sends HTTP/1.1 chunks and explicit trailers.

Implementation Copy for BodyMode

impl Copy for BodyMode

HeaderControl

pub union HeaderControl<'value>

A generated field policy that distinguishes omission from a default.

Default

HeaderControl<'value>.Default: HeaderControl<'value>

Generates the documented default value.

Omit

HeaderControl<'value>.Omit: HeaderControl<'value>

Deliberately omits the field when the protocol permits it.

Value

HeaderControl<'value>.Value { value: &'value [u8] }: HeaderControl<'value>

Uses one explicit validated value.

Field value

pub value: &'value [u8]

The caller-owned semantic field bytes.

Implementation Copy for silk/http_request.HeaderControl<'value>

impl Copy for silk/http_request.HeaderControl<'value>

Authorization

pub union Authorization<'value>

One explicit authorization source.

Absent

Authorization<'value>.Absent: Authorization<'value>

Sends no generated authorization field.

Value

Authorization<'value>.Value { value: &'value [u8] }: Authorization<'value>

Sends one explicit validated field value.

Field value

pub value: &'value [u8]

The complete authorization field value.

Basic

Authorization<'value>.Basic { username: &'value [u8], password: &'value [u8] }: Authorization<'value>

Encodes caller-selected username and password bytes.

Field username

pub username: &'value [u8]

Username bytes without colon or controls.

Field password

pub password: &'value [u8]

Password bytes without controls.

Implementation Copy for silk/http_request.Authorization<'value>

impl Copy for silk/http_request.Authorization<'value>

BasicSecurity

pub enum BasicSecurity

Explicit permission to send Basic credentials without TLS.

RequireTls

RequireTls = 0

Rejects Basic credentials for a plaintext origin.

AllowInsecureBasic

AllowInsecureBasic = 1

Permits plaintext Basic without changing HTTPS authentication.

HeaderPolicy

pub struct HeaderPolicy<'value>

Policy for generated request fields and connection persistence.

Field host

pub host: silk/http_request.HeaderControl<'value>

Defaults to the normalized origin authority; HTTP/1.1 cannot omit it.

Field userAgent

pub userAgent: silk/http_request.HeaderControl<'value>

Defaults to silk-http/1.

Field accept

pub accept: silk/http_request.HeaderControl<'value>

Defaults to */*.

Field authorization

pub authorization: silk/http_request.Authorization<'value>

One optional explicit authorization source.

Field basicSecurity

pub basicSecurity: BasicSecurity

Requires TLS for Basic unless explicitly overridden.

Field http10KeepAlive

pub http10KeepAlive: bool

Permits HTTP/1.0 keep-alive; HTTP/1.1 uses normal persistence.

Associated function HeaderPolicy.defaults

pub fn defaults<'value>() -> silk/http_request.HeaderPolicy<'value>

Returns generated defaults, absent authorization, and plaintext Basic rejection.

Implementation Copy for silk/http_request.HeaderPolicy<'value>

impl Copy for silk/http_request.HeaderPolicy<'value>

RequestError

pub union RequestError

A precise preflight failure with no network side effects.

Value

RequestError.Value { error: ValueError }: RequestError

A shared HTTP value failed validation.

Field error

pub error: ValueError

The original value failure.

Origin

RequestError.Origin { error: OriginError }: RequestError

An origin could not be constructed or serialized.

Field error

pub error: OriginError

The original origin failure.

Basic

RequestError.Basic { error: BasicError }: RequestError

Credentials failed strict Basic encoding.

Field error

pub error: BasicError

The credential failure, without credential bytes.

ConflictingHeader

RequestError.ConflictingHeader: RequestError

A caller field conflicts with generated policy.

ConflictingAuthority

RequestError.ConflictingAuthority: RequestError

The explicit Host differs from the connection origin.

MissingHost

RequestError.MissingHost: RequestError

HTTP/1.1 cannot omit Host.

InvalidBodyMode

RequestError.InvalidBodyMode: RequestError

The body or continue mode is unavailable for the selected version.

MultipleAuthorization

RequestError.MultipleAuthorization: RequestError

More than one authorization source was supplied.

InsecureBasic

RequestError.InsecureBasic: RequestError

Plaintext Basic lacks explicit permission.

ProxyAuthorization

RequestError.ProxyAuthorization: RequestError

A direct request supplies proxy credentials.

CredentialLimit

RequestError.CredentialLimit: RequestError

Credential bytes exceed the finite budget.

HeaderLimit

RequestError.HeaderLimit: RequestError

Generated or copied fields exceed the configured finite count.

InvalidTarget

RequestError.InvalidTarget: RequestError

A direct request uses an absolute target for another origin.

PreparedRequest

pub struct PreparedRequest

One owned, origin-bound, preflighted head with unforgeable framing policy.

Method PreparedRequest.bytes

pub fn bytes<'a>(self: &'a PreparedRequest) -> &'a [u8]

Borrows the serialized request head until this owner is dropped.

Method PreparedRequest.origin

pub fn origin<'life0>(self: &'life0 PreparedRequest) -> Origin

Returns the logical request origin used for target, Host, and origin credentials.

Method PreparedRequest.physicalPeer

pub fn physicalPeer<'life0>(self: &'life0 PreparedRequest) -> Origin

Returns the physical peer on whose connection this request is admitted.

Method PreparedRequest.version

pub fn version<'life0>(self: &'life0 PreparedRequest) -> Version

Returns the admitted HTTP version.

Method PreparedRequest.bodyMode

pub fn bodyMode<'life0>(self: &'life0 PreparedRequest) -> BodyMode

Returns the exact selected body delimiter.

Method PreparedRequest.require100

pub fn require100<'life0>(self: &'life0 PreparedRequest) -> bool

Returns whether the head contains the generated 100-continue expectation.

prepare

pub effect<'env> fn prepare<'value: 'env, 'life1: 'env, 'life2: 'env, 'life3: 'env, 'env>(origin: &'life1 silk/http_origin.Origin, version: Version, method: silk/http.Method<'value>, target: silk/http_target.RequestTarget<'value>, headers: &'life2 silk/http_headers.Headers<'value>, policy: &'life3 silk/http_request.HeaderPolicy<'value>, body: BodyMode, require100: bool, limits: Limits, maxHeadBytes: usize, maxCredentialBytes: usize) -> PreparedRequest ! RequestError | OutOfMemoryError ? &mut Allocator

Validates and serializes one request before any transport operation.

Details

Caller fields preserve order. Host, User-Agent, Accept, framing, Expect, and Connection belong to policy and cannot also occur in headers. Output owns all borrowed input bytes. maxHeadBytes and maxCredentialBytes bound owned head and credential storage.

prepareForward

pub effect<'env> fn prepareForward<'configuration: 'env, 'value: 'env, 'life2: 'env, 'life3: 'env, 'life4: 'env, 'life5: 'env, 'env>(route: &'life2 silk/http_proxy.Route<'configuration>, uri: &'life3 silk/uri.Uri<'value>, version: Version, method: silk/http.Method<'value>, headers: &'life4 silk/http_headers.Headers<'value>, policy: &'life5 silk/http_request.HeaderPolicy<'value>, body: BodyMode, require100: bool, limits: Limits, maxHeadBytes: usize, maxCredentialBytes: usize) -> PreparedRequest ! ProxyError | RequestError | OutOfMemoryError ? &mut Allocator

Prepares one Forward route as an origin-bound absolute-form request for its plain proxy peer.

Details

The sealed route is the only source of the physical peer and Proxy-Authorization. The original URI spelling is preserved except that user information and fragments are excluded and an empty path becomes /. Forward preparation always generates the logical-origin Host, including for HTTP/1.0.

prepareConnect

pub effect<'env> fn prepareConnect<'configuration: 'env, 'life1: 'env, 'env>(route: &'life1 silk/http_proxy.Route<'configuration>, limits: Limits, maxHeadBytes: usize, maxCredentialBytes: usize) -> PreparedRequest ! ProxyError | RequestError | OutOfMemoryError ? &mut Allocator

Prepares the one body-free HTTP/1.1 CONNECT head admitted by a Tunnel route.

Details

The authority-form target and Host are both derived from the route's normalized original origin and always include its effective port. Callers cannot supply fields, a body, a physical peer, or proxy credentials.

fromUri

pub effect<'env> fn fromUri<'value: 'env, 'life1: 'env, 'life2: 'env, 'life3: 'env, 'env>(uri: &'life1 silk/uri.Uri<'value>, version: Version, method: silk/http.Method<'value>, headers: &'life2 silk/http_headers.Headers<'value>, policy: &'life3 silk/http_request.HeaderPolicy<'value>, body: BodyMode, require100: bool, limits: Limits, maxHeadBytes: usize, maxCredentialBytes: usize) -> PreparedRequest ! RequestError | OutOfMemoryError ? &mut Allocator

Converts a validated URI to an origin-form request with query and no fragment.

On this page