Silk

silk/http

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.

Validated, byte-preserving HTTP/1.x scalar values, fields, and message heads.

When to use

Use these values to share HTTP semantics between parsers, clients, and servers. Parsing and validation borrow caller storage; use the owned head copies when values must outlive that input.

Details

Methods remain open case-sensitive tokens, fields retain exact octets, and statuses retain every code from 100 through 599. This module applies no framing, transport, or connection policy.

Gotchas

Header.make receives semantic field values after wire OWS has been removed. It rejects CR, LF, NUL, DEL, other forbidden controls, and leading or trailing OWS.

Examples

Preserve protocol spelling

import silk.http { Method, Version }

pub fn main() -> i32 {
  let version = Version.Http11
  let method = Method.patch()
  if Version.format(&version) != "HTTP/1.1" { return 1 }
  if Method.format(&method) != "PATCH" { return 2 }
  return 42
}

Import as Version with import silk.http { Version }.

Public declarations: 13.

ValueComponent

pub enum ValueComponent

The component of an HTTP value that failed validation.

Version

Version = 0

An HTTP version token.

Method

Method = 1

A request method token.

Status

Status = 2

A numeric response status.

HeaderName

HeaderName = 3

A field name.

HeaderValue

HeaderValue = 4

A field value.

ReasonPhrase

ReasonPhrase = 5

An optional response reason phrase.

Headers

Headers = 6

An ordered field collection.

Target

Target = 7

A request target.

Authority

Authority = 8

An HTTP authority.

Host

Host = 9

A Host field.

Metadata

Metadata = 10

A structured metadata field value.

LimitKind

pub enum LimitKind

The finite limit whose allowed count was exceeded.

MethodBytes

MethodBytes = 0

Maximum method bytes.

TargetBytes

TargetBytes = 1

Maximum request-target bytes.

NameBytes

NameBytes = 2

Maximum field-name bytes.

ValueBytes

ValueBytes = 3

Maximum field-value or reason bytes.

Fields

Fields = 4

Maximum field count.

FieldBytes

FieldBytes = 5

Maximum aggregate name-plus-value bytes.

OwnedBytes

OwnedBytes = 6

Maximum owned payload and index bytes.

UniqueField

UniqueField = 7

At most one matching field was required.

ValueReason

pub union ValueReason

A closed semantic HTTP value failure reason.

InvalidToken

ValueReason.InvalidToken: ValueReason

A token is empty or contains a byte outside tchar.

InvalidValueByte

ValueReason.InvalidValueByte: ValueReason

A value contains a forbidden byte.

UnsupportedVersion

ValueReason.UnsupportedVersion: ValueReason

A version is not HTTP/1.0 or HTTP/1.1.

InvalidStatus

ValueReason.InvalidStatus: ValueReason

A response code is outside 100 through 599.

InvalidTarget

ValueReason.InvalidTarget: ValueReason

A request target has invalid syntax.

InvalidAuthority

ValueReason.InvalidAuthority: ValueReason

An HTTP authority has invalid syntax.

InvalidPort

ValueReason.InvalidPort: ValueReason

A port is absent, empty, nonnumeric, or outside its accepted range.

MethodTargetMismatch

ValueReason.MethodTargetMismatch: ValueReason

The request method cannot use the supplied target form.

MissingHost

ValueReason.MissingHost: ValueReason

HTTP/1.1 has no Host field.

DuplicateHost

ValueReason.DuplicateHost: ValueReason

More than one Host field is present.

LimitExceeded

ValueReason.LimitExceeded { limit: LimitKind, allowed: usize, attempted: usize }: ValueReason

One explicit finite limit was exceeded.

Field limit

pub limit: LimitKind

The rejected limit.

Field allowed

pub allowed: usize

The configured maximum.

Field attempted

pub attempted: usize

The attempted count.

SizeOverflow

ValueReason.SizeOverflow: ValueReason

Checked size arithmetic overflowed usize.

OutputTooSmall

ValueReason.OutputTooSmall { required: usize, available: usize }: ValueReason

Caller-owned output cannot hold the complete serialization.

Field required

pub required: usize

Complete required output bytes.

Field available

pub available: usize

Available caller output bytes.

Implementation Copy for ValueReason

impl Copy for ValueReason

ValueError

pub struct ValueError

A semantic HTTP value failure with source location information.

Field reason

pub reason: ValueReason

The recovery-oriented failure category.

Field component

pub component: ValueComponent

The value component being validated.

Field fieldIndex

pub fieldIndex: silk/option.Option<usize>

The source field ordinal when the error came from a collection.

Field offset

pub offset: usize

The zero-based component byte offset.

Version

pub enum Version

One supported HTTP protocol version.

Http10

Http10 = 0

HTTP/1.0.

Http11

Http11 = 1

HTTP/1.1.

Associated function Version.parse

pub fn parse<'life0>(text: string<'life0>) -> silk/result.Result<silk/http.Version, silk/http.ValueError>

Parses exactly HTTP/1.0 or HTTP/1.1.

Method Version.format

pub fn format<'life0>(self: &'life0 Version) -> string<'static>

Formats one supported version as its exact protocol token.

Method

pub struct Method<'text>

A borrowed open HTTP method token with preserved spelling.

Associated function Method.parse

pub fn parse<'text>(text: string<'text>, maxBytes: usize) -> silk/result.Result<silk/http.Method<'text>, silk/http.ValueError>

Validates a nonempty tchar token within maxBytes and borrows it unchanged.

Method Method.format

pub fn format<'text, 'life1>(self: &'life1 Method<'text>) -> string<'text>

Borrows the original method spelling.

Method Method.equals

pub fn equals<'text, 'life1, 'life2, 'life3>(self: &'life1 Method<'text>, other: &'life2 silk/http.Method<'life3>) -> bool

Compares method spelling case-sensitively.

Associated function Method.get

pub fn get() -> silk/http.Method<'static>

Returns the standard GET method value.

Associated function Method.head

pub fn head() -> silk/http.Method<'static>

Returns the standard HEAD method value.

Associated function Method.post

pub fn post() -> silk/http.Method<'static>

Returns the standard POST method value.

Associated function Method.put

pub fn put() -> silk/http.Method<'static>

Returns the standard PUT method value.

Associated function Method.delete

pub fn delete() -> silk/http.Method<'static>

Returns the standard DELETE method value.

Associated function Method.connect

pub fn connect() -> silk/http.Method<'static>

Returns the standard CONNECT method value.

Associated function Method.options

pub fn options() -> silk/http.Method<'static>

Returns the standard OPTIONS method value.

Associated function Method.trace

pub fn trace() -> silk/http.Method<'static>

Returns the standard TRACE method value.

Associated function Method.patch

pub fn patch() -> silk/http.Method<'static>

Returns the standard PATCH method value.

Implementation Copy for silk/http.Method<'text>

impl Copy for silk/http.Method<'text>

StatusClass

pub enum StatusClass

The protocol class of a response status.

Informational

Informational = 0

1xx informational.

Successful

Successful = 1

2xx successful.

Redirection

Redirection = 2

3xx redirection.

ClientError

ClientError = 3

4xx client error.

ServerError

ServerError = 4

5xx server error.

Status

pub struct Status

A response status retaining registered and unregistered valid codes.

Associated function Status.fromCode

pub fn fromCode(code: u16) -> silk/result.Result<silk/http.Status, silk/http.ValueError>

Constructs a status from any code in the inclusive 100 through 599 range.

Method Status.code

pub fn code<'life0>(self: &'life0 Status) -> u16

Returns the preserved numeric status code.

Method Status.class

pub fn class<'life0>(self: &'life0 Status) -> StatusClass

Returns the status class derived from the hundreds digit.

Implementation Copy for Status

impl Copy for Status

pub struct Header<'value>

A validated header field borrowing its exact name spelling and raw value octets.

Associated function Header.make

pub fn make<'value>(name: string<'value>, value: &'value [u8], limits: Limits) -> silk/result.Result<silk/http.Header<'value>, silk/http.ValueError>

Validates one semantic field after wire OWS removal and borrows it unchanged.

Method Header.name

pub fn name<'value, 'life1>(self: &'life1 Header<'value>) -> string<'value>

Borrows the original field-name spelling.

Method Header.value

pub fn value<'value, 'life1>(self: &'life1 Header<'value>) -> &'value [u8]

Borrows the exact validated field-value octets.

Implementation Copy for silk/http.Header<'value>

impl Copy for silk/http.Header<'value>

RequestHead

pub struct RequestHead<'value>

A validated request head without body, framing, connection, or exchange state.

Associated function RequestHead.make

pub fn make<'value>(version: Version, method: silk/http.Method<'value>, target: silk/http_target.RequestTarget<'value>, headers: silk/http_headers.Headers<'value>) -> silk/result.Result<silk/http.RequestHead<'value>, silk/http.ValueError>

Combines validated request components and enforces the HTTP/1.1 Host requirement.

Method RequestHead.version

pub fn version<'value, 'life1>(self: &'life1 RequestHead<'value>) -> Version

Returns the request version.

Method RequestHead.method

pub fn method<'value, 'life1>(self: &'life1 RequestHead<'value>) -> silk/http.Method<'value>

Returns the borrowed request method.

Method RequestHead.target

pub fn target<'value, 'life1>(self: &'life1 RequestHead<'value>) -> silk/http_target.RequestTarget<'value>

Returns the borrowed request target.

Method RequestHead.headers

pub fn headers<'value, 'life1>(self: &'life1 RequestHead<'value>) -> silk/http_headers.Headers<'value>

Returns the borrowed ordered fields.

Method RequestHead.copy

pub effect<'env> fn copy<'value: 'env, 'life1: 'env, 'env>(self: &'life1 RequestHead<'value>, limits: Limits) -> silk/result.Result<silk/http.OwnedRequestHead, silk/http.ValueError> ! OutOfMemoryError ? &mut Allocator

Copies the complete request head into independent bounded storage.

Implementation Copy for silk/http.RequestHead<'value>

impl Copy for silk/http.RequestHead<'value>

OwnedRequestHead

pub struct OwnedRequestHead

An independently owned request head whose views borrow only this value.

Method OwnedRequestHead.view

pub fn view<'value>(self: &'value OwnedRequestHead) -> silk/http.RequestHead<'value>

Reconstructs a validated request view tied to this owner without allocation.

ResponseHead

pub struct ResponseHead<'value>

A validated response head without body, framing, connection, or exchange state.

Associated function ResponseHead.make

pub fn make<'value>(version: Version, status: Status, reason: silk/option.Option<&'value [u8]>, headers: silk/http_headers.Headers<'value>, limits: Limits) -> silk/result.Result<silk/http.ResponseHead<'value>, silk/http.ValueError>

Validates an optional reason phrase and combines response metadata.

Method ResponseHead.version

pub fn version<'value, 'life1>(self: &'life1 ResponseHead<'value>) -> Version

Returns the response version.

Method ResponseHead.status

pub fn status<'value, 'life1>(self: &'life1 ResponseHead<'value>) -> Status

Returns the response status.

Method ResponseHead.reason

pub fn reason<'value, 'life1>(self: &'life1 ResponseHead<'value>) -> silk/option.Option<&'value [u8]>

Returns the exact optional reason-phrase bytes.

Method ResponseHead.headers

pub fn headers<'value, 'life1>(self: &'life1 ResponseHead<'value>) -> silk/http_headers.Headers<'value>

Returns the borrowed ordered fields.

Method ResponseHead.copy

pub effect<'env> fn copy<'value: 'env, 'life1: 'env, 'env>(self: &'life1 ResponseHead<'value>, limits: Limits) -> silk/result.Result<silk/http.OwnedResponseHead, silk/http.ValueError> ! OutOfMemoryError ? &mut Allocator

Copies the complete response head into independent bounded storage.

Method ResponseHead.copyMatchingHeaders

pub effect<'env> fn copyMatchingHeaders<'value: 'env, 'life1: 'env, 'env>(self: &'life1 ResponseHead<'value>, name: string<'value>, limits: Limits) -> silk/result.Result<silk/http.OwnedResponseHead, silk/http.ValueError> ! OutOfMemoryError ? &mut Allocator

Copies the response status, reason, and only matching fields into independent storage.

Details

Matching is ASCII case-insensitive. Duplicate matches remain distinct and preserve wire order. The total-owned limit covers copied reason bytes, field payload, and field records.

OwnedResponseHead

pub struct OwnedResponseHead

An independently owned response head whose views borrow only this value.

Method OwnedResponseHead.view

pub fn view<'value>(self: &'value OwnedResponseHead) -> silk/http.ResponseHead<'value>

Reconstructs a validated response view tied to this owner without allocation.

On this page

When to useDetailsGotchasExamplesPreserve protocol spellingValueComponentVersionMethodStatusHeaderNameHeaderValueReasonPhraseHeadersTargetAuthorityHostMetadataLimitKindMethodBytesTargetBytesNameBytesValueBytesFieldsFieldBytesOwnedBytesUniqueFieldValueReasonInvalidTokenInvalidValueByteUnsupportedVersionInvalidStatusInvalidTargetInvalidAuthorityInvalidPortMethodTargetMismatchMissingHostDuplicateHostLimitExceededField limitField allowedField attemptedSizeOverflowOutputTooSmallField requiredField availableImplementation Copy for ValueReasonValueErrorField reasonField componentField fieldIndexField offsetVersionHttp10Http11Associated function Version.parseMethod Version.formatMethodAssociated function Method.parseMethod Method.formatMethod Method.equalsAssociated function Method.getAssociated function Method.headAssociated function Method.postAssociated function Method.putAssociated function Method.deleteAssociated function Method.connectAssociated function Method.optionsAssociated function Method.traceAssociated function Method.patchImplementation Copy for silk/http.Method<'text>StatusClassInformationalSuccessfulRedirectionClientErrorServerErrorStatusAssociated function Status.fromCodeMethod Status.codeMethod Status.classImplementation Copy for StatusHeaderAssociated function Header.makeMethod Header.nameMethod Header.valueImplementation Copy for silk/http.Header<'value>RequestHeadAssociated function RequestHead.makeMethod RequestHead.versionMethod RequestHead.methodMethod RequestHead.targetMethod RequestHead.headersMethod RequestHead.copyImplementation Copy for silk/http.RequestHead<'value>OwnedRequestHeadMethod OwnedRequestHead.viewResponseHeadAssociated function ResponseHead.makeMethod ResponseHead.versionMethod ResponseHead.statusMethod ResponseHead.reasonMethod ResponseHead.headersMethod ResponseHead.copyMethod ResponseHead.copyMatchingHeadersDetailsOwnedResponseHeadMethod OwnedResponseHead.view