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 ValueComponentThe component of an HTTP value that failed validation.
Version
Version = 0An HTTP version token.
Method
Method = 1A request method token.
Status
Status = 2A numeric response status.
HeaderName
HeaderName = 3A field name.
HeaderValue
HeaderValue = 4A field value.
ReasonPhrase
ReasonPhrase = 5An optional response reason phrase.
Headers
Headers = 6An ordered field collection.
Target
Target = 7A request target.
Authority
Authority = 8An HTTP authority.
Host
Host = 9A Host field.
Metadata
Metadata = 10A structured metadata field value.
LimitKind
pub enum LimitKindThe finite limit whose allowed count was exceeded.
MethodBytes
MethodBytes = 0Maximum method bytes.
TargetBytes
TargetBytes = 1Maximum request-target bytes.
NameBytes
NameBytes = 2Maximum field-name bytes.
ValueBytes
ValueBytes = 3Maximum field-value or reason bytes.
Fields
Fields = 4Maximum field count.
FieldBytes
FieldBytes = 5Maximum aggregate name-plus-value bytes.
OwnedBytes
OwnedBytes = 6Maximum owned payload and index bytes.
UniqueField
UniqueField = 7At most one matching field was required.
ValueReason
pub union ValueReasonA closed semantic HTTP value failure reason.
InvalidToken
ValueReason.InvalidToken: ValueReasonA token is empty or contains a byte outside tchar.
InvalidValueByte
ValueReason.InvalidValueByte: ValueReasonA value contains a forbidden byte.
UnsupportedVersion
ValueReason.UnsupportedVersion: ValueReasonA version is not HTTP/1.0 or HTTP/1.1.
InvalidStatus
ValueReason.InvalidStatus: ValueReasonA response code is outside 100 through 599.
InvalidTarget
ValueReason.InvalidTarget: ValueReasonA request target has invalid syntax.
InvalidAuthority
ValueReason.InvalidAuthority: ValueReasonAn HTTP authority has invalid syntax.
InvalidPort
ValueReason.InvalidPort: ValueReasonA port is absent, empty, nonnumeric, or outside its accepted range.
MethodTargetMismatch
ValueReason.MethodTargetMismatch: ValueReasonThe request method cannot use the supplied target form.
MissingHost
ValueReason.MissingHost: ValueReasonHTTP/1.1 has no Host field.
DuplicateHost
ValueReason.DuplicateHost: ValueReasonMore than one Host field is present.
LimitExceeded
ValueReason.LimitExceeded { limit: LimitKind, allowed: usize, attempted: usize }: ValueReasonOne explicit finite limit was exceeded.
Field limit
pub limit: LimitKindThe rejected limit.
Field allowed
pub allowed: usizeThe configured maximum.
Field attempted
pub attempted: usizeThe attempted count.
SizeOverflow
ValueReason.SizeOverflow: ValueReasonChecked size arithmetic overflowed usize.
OutputTooSmall
ValueReason.OutputTooSmall { required: usize, available: usize }: ValueReasonCaller-owned output cannot hold the complete serialization.
Field required
pub required: usizeComplete required output bytes.
Field available
pub available: usizeAvailable caller output bytes.
Implementation Copy for ValueReason
impl Copy for ValueReasonValueError
pub struct ValueErrorA semantic HTTP value failure with source location information.
Field reason
pub reason: ValueReasonThe recovery-oriented failure category.
Field component
pub component: ValueComponentThe 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: usizeThe zero-based component byte offset.
Version
pub enum VersionOne supported HTTP protocol version.
Http10
Http10 = 0HTTP/1.0.
Http11
Http11 = 1HTTP/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>) -> boolCompares 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 StatusClassThe protocol class of a response status.
Informational
Informational = 01xx informational.
Successful
Successful = 12xx successful.
Redirection
Redirection = 23xx redirection.
ClientError
ClientError = 34xx client error.
ServerError
ServerError = 45xx server error.
Status
pub struct StatusA 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) -> u16Returns the preserved numeric status code.
Method Status.class
pub fn class<'life0>(self: &'life0 Status) -> StatusClassReturns the status class derived from the hundreds digit.
Implementation Copy for Status
impl Copy for StatusHeader
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>) -> VersionReturns 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 AllocatorCopies 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 OwnedRequestHeadAn 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>) -> VersionReturns the response version.
Method ResponseHead.status
pub fn status<'value, 'life1>(self: &'life1 ResponseHead<'value>) -> StatusReturns 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 AllocatorCopies 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 AllocatorCopies 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 OwnedResponseHeadAn 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.