API reference Dodo 0.1.4

std/web

Public declarations, types, methods, and source contracts for std/web.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/web"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
http std/http web.dodo
io std/io web.dodo
raw core/bytes web.dodo
utf8 std/text web.dodo

Error

Enum · Source

Portable routing: byte paths decoded exactly once into caller storage. No allocation, I/O, clock, filesystem, TLS, or scheduler dependency.

pub enum Error {
    InvalidPath, InvalidPattern, InvalidMethod, AmbiguousRoute, BufferFull,
    NotFound, MethodNotAllowed, Cancelled, Handler, InvalidProgress,
    InvalidQuery, QueryLimit, InvalidHeader, InvalidStatus, HeaderLimit
}

decode_path

Function · Source

Query remains separate. Encoded separators, controls, backslashes, fragments, invalid UTF-8, and dot segments are rejected, never silently normalized. Failure can modify a prefix; only the successful returned prefix is a path.

pub fn decode_path(target: &[u8], output: &mut[u8]) -> usize!Error

validate_path

Function · Source

pub fn validate_path(path: &[u8]) -> void!Error

Path

Struct · Source

A borrowed proof of validation; the bytes cannot change while it is live.

pub struct Path {
    // Private implementation fields omitted.
}

Path.new

Function · Source

pub fn new(data: &[u8]) -> Path!Error from(data)

Path.decode

Function · Source

pub fn decode(target: &[u8], output: &mut[u8]) -> Path!Error from(output)

Path.bytes

Function · Source

pub fn bytes(&self) -> &[u8]

valid_method

Function · Source

pub fn valid_method(method: &[u8]) -> bool

Route

Struct · Source

pub struct Route {
    pub method: &[u8]
    pub pattern: &[u8]
    pub id: usize
}

Match

Struct · Source

pub struct Match {
    pub index: usize
    pub id: usize
    pub head: bool
}

Parameter

Struct · Source

pub struct Parameter {
    pub start: usize
    pub end: usize
}

Router

Struct · Source

pub struct Router {
    // Private implementation fields omitted.
}

Router.new

Function · Source

pub fn new(routes: &[Route]) -> Router!Error from(routes)

Router.indexed

Function · Source

Caller-owned hash table for literals and dynamic literal prefixes. No allocation, route-count ceiling, or probabilistic match is involved.

pub fn indexed(routes: &[Route], storage: &mut[usize]) -> Router!Error from(routes, storage)

Router.find

Function · Source

pub fn find(&self, method: &[u8], path: &[u8]) -> Match!Error

Router.find_path

Function · Source

pub fn find_path(&self, method: &[u8], validated: &Path) -> Match!Error

Router.parameter

Function · Source

Returns offsets in the supplied decoded path, never an unchecked pointer.

pub fn parameter(&self, route: usize, path: &[u8], name: &[u8]) -> Option<Parameter>

RouteTable

Struct · Source

pub struct RouteTable {
    // Private implementation fields omitted.
}

RouteTable.new

Function · Source

pub fn new() -> RouteTable from(static)

RouteTable.routes

Function · Source

pub fn routes(&self) -> &[Route]

RouteTable.router

Function · Source

pub fn router(&self) -> Router from(self)

RouteTable.insert

Function · Source

pub fn insert(self, method: &[u8], pattern: &[u8]) -> RouteInsertion from(self, method, pattern)

RouteInsertion

Struct · Source

pub struct RouteInsertion {
    pub table: RouteTable
    pub problem: Option<Error>
}

Context

Struct · Source

pub struct Context {
    pub method: &[u8]
    pub path: &[u8]
    pub route_id: usize
    pub request_id: u64
    pub cancelled: bool
}

Failure

Struct · Source

Buffered application failures retain the protocol or UTF-8 diagnostic. Routing/streaming keep the small Error enum above for compatibility.

pub struct Failure {
    pub kind: Error
    pub protocol: Option<http.Error>
    pub encoding: Option<utf8.Error>
    // Zero keeps internal failures private (500); reject() sets an HTTP status.
    pub response_status: u16
}

Failure.status

Function · Source

pub fn status(&self) -> u16

Failure.format

Function · Source

pub fn format<F>(&self, output: &mut F) -> void!io.Error

failure

Function · Source

pub fn failure(kind: Error) -> Failure

reject

Function · Source

An intentional HTTP rejection. Invalid codes remain internal errors.

pub fn reject(status: u16) -> Failure

protocol_failure

Function · Source

pub fn protocol_failure(kind: Error, reason: http.Error) -> Failure

Fields

Struct · Source

NUL-delimited name/value pairs. Only validated fields enter this storage. Mutators copy bytes, never retain their arguments. A failed append is atomic.

pub struct Fields {
    // Private implementation fields omitted.
}

Fields.new

Function · Source

pub fn new(data: &mut[u8], limit: usize) -> Fields from(data)

Fields.resume

Function · Source

pub fn resume(data: &mut[u8], used: usize, count: usize, limit: usize) -> Fields!Failure from(data)

Fields.bytes

Function · Source

pub fn bytes(&self) -> &[u8]

Fields.len

Function · Source

pub fn len(&self) -> usize

Fields.next

Function · Source

pub fn next(&self, cursor: &mut usize) -> Option<http.Header> from(self)

Fields.append

Function · Source

pub fn append(&mut self, name: &[u8], value: &[u8]) -> void!Failure

field_at

Function · Source

pub fn field_at(data: &[u8], index: usize) -> Option<http.Header> from(data)

field_next

Function · Source

Start at zero; each successful call advances past one complete field. Truncated fields and exhaustion return none and leave the cursor at the end.

pub fn field_next(data: &[u8], cursor: &mut usize) -> Option<http.Header> from(data)

decode_query

Function · Source

Form-style query: split on &, then first =, then percent-decode once and turn + into space. Empty components are skipped; bare keys have empty values. Names are case sensitive. Controls and invalid UTF-8 are rejected. Failure may modify a prefix: only the successful prefix may be used.

pub fn decode_query(raw: &[u8], output: &mut[u8], limit: usize) -> usize!Failure

Request

Struct · Source

pub struct Request {
    pub route_id: usize
    pub request_id: u64
    pub cancelled: bool
    // Private implementation fields omitted.
}

Request.new

Function · Source

Header/query storage is the initialized prefix of Fields/decode_query.

pub fn new(method: &[u8], path: &[u8], headers: &[u8], query: &[u8], body: &[u8],
    router: &Router, route: usize, route_id: usize, request_id: u64) -> Request from(method, path, headers, query, body, router)

Request.method

Function · Source

pub fn method(&self) -> &[u8]

Request.path

Function · Source

pub fn path(&self) -> &[u8]

Request.body

Function · Source

pub fn body(&self) -> &[u8]

Request.header

Function · Source

pub fn header(&self, name: &[u8], occurrence: usize) -> Option<&[u8]> from(self)

Request.query

Function · Source

pub fn query(&self, name: &[u8], occurrence: usize) -> Option<&[u8]> from(self)

Request.header_value

Function · Source

Common single-value access; occurrence-based access remains available.

pub fn header_value(&self, name: &[u8]) -> Option<&[u8]> from(self)

Request.query_value

Function · Source

pub fn query_value(&self, name: &[u8]) -> Option<&[u8]> from(self)

Request.query_or

Function · Source

pub fn query_or(&self, name: &[u8], fallback: &[u8]) -> &[u8] from(self, fallback)

Request.require_query

Function · Source

pub fn require_query(&self, name: &[u8]) -> &[u8]!Failure from(self)

Request.require_header

Function · Source

pub fn require_header(&self, name: &[u8]) -> &[u8]!Failure from(self)

Request.param

Function · Source

pub fn param(&self, name: &[u8]) -> &[u8]!Failure from(self)

Request.param_u64

Function · Source

pub fn param_u64(&self, name: &[u8]) -> u64!Failure

Request.query_u64

Function · Source

pub fn query_u64(&self, name: &[u8], fallback: u64) -> u64!Failure

Request.parameter

Function · Source

pub fn parameter(&self, name: &[u8]) -> Option<&[u8]> from(self)

Response

Struct · Source

Response owns no allocation and stores no handler borrows. Headers and body are copied into explicit caller storage; getters borrow only this response.

pub struct Response {
    // Private implementation fields omitted.
}

Response.new

Function · Source

pub fn new(headers: &mut[u8], header_fields: usize, body: &mut[u8]) -> Response from(headers, body)

Response.status

Function · Source

pub fn status(&self) -> u16

Response.set_status

Function · Source

pub fn set_status(&mut self, code: u16) -> void!Failure

Response.header

Function · Source

Append preserves duplicates in insertion order, including Set-Cookie. Framing and connection management belong to the runner.

pub fn header(&mut self, name: &[u8], value: &[u8]) -> void!Failure

Response.header_at

Function · Source

pub fn header_at(&self, index: usize) -> Option<http.Header> from(self)

Response.header_next

Function · Source

pub fn header_next(&self, cursor: &mut usize) -> Option<http.Header> from(self)

Response.header_bytes

Function · Source

pub fn header_bytes(&self) -> usize

Response.header_value

Function · Source

pub fn header_value(&self, name: &[u8]) -> Option<&[u8]> from(self)

Response.body

Function · Source

pub fn body(&self) -> &[u8]

Response.bytes

Function · Source

pub fn bytes(&mut self, body: &[u8]) -> void!Failure

Response.append

Function · Source

Append supports small dynamic responses without a second scratch buffer.

pub fn append(&mut self, body: &[u8]) -> void!Failure

Response.empty

Function · Source

pub fn empty(&mut self, status: u16) -> void!Failure

Response.redirect

Function · Source

pub fn redirect(&mut self, location: &[u8]) -> void!Failure

Response.redirect_to

Function · Source

pub fn redirect_to(&mut self, location: &[u8], status: u16) -> void!Failure

Response.text

Function · Source

pub fn text(&mut self, body: &[u8]) -> void!Failure

Response.html

Function · Source

pub fn html(&mut self, body: &[u8]) -> void!Failure

Response.json

Function · Source

Already serialized JSON; validates UTF-8, not JSON syntax.

pub fn json(&mut self, body: &[u8]) -> void!Failure

bodyless

Function · Source

Shared buffered-response policy for hosted and in-process dispatch.

pub fn bodyless(method: &[u8], status: u16) -> bool

handle

Function · Source

The callback cannot retain request or response borrows in handler state.

pub fn handle<H>(handler: &mut H, request: &mut Request, response: &mut Response) -> void!Failure

Reply

Struct · Source

Static responses are ordinary handlers and work with every runner.

pub struct Reply {
    // Private implementation fields omitted.
}

Reply.status

Function · Source

pub fn status(self, code: u16) -> Reply from(self)

Reply.handle

Function · Source

pub fn handle(&mut self, request: &mut Request, response: &mut Response) -> void!Failure

text

Function · Source

pub fn text(body: &[u8]) -> Reply from(body)

html

Function · Source

pub fn html(body: &[u8]) -> Reply from(body)

json

Function · Source

pub fn json(body: &[u8]) -> Reply from(body)

bytes

Function · Source

pub fn bytes(body: &[u8]) -> Reply from(body)

redirect

Function · Source

pub fn redirect(location: &[u8]) -> Reply from(location)

WithMiddleware

Struct · Source

pub struct WithMiddleware<H, M> {
    pub handler: H
    pub middleware: M
}

WithMiddleware.handle

Function · Source

pub fn handle(&mut self, request: &mut Request, response: &mut Response) -> void!Failure

with

Function · Source

pub fn with<H, M>(handler: H, middleware: M) -> WithMiddleware<H, M> from(handler, middleware)

Chain

Struct · Source

pub struct Chain<A, B> {
    pub outer: A
    pub inner: B
}

Chain.before

Function · Source

pub fn before(&mut self, request: &mut Request) -> void!Failure

Chain.after

Function · Source

pub fn after(&mut self, request: &mut Request, status: u16)

NoMiddleware

Struct · Source

pub struct NoMiddleware {

}

NoMiddleware.before

Function · Source

pub fn before(&mut self, request: &mut Request) -> void!Failure

NoMiddleware.after

Function · Source

pub fn after(&mut self, request: &mut Request, status: u16)

dispatch

Function · Source

pub fn dispatch<M, H>(middleware: &mut M, handler: &mut H, request: &mut Request, response: &mut Response) -> void!Failure

ErrorResponses

Struct · Source

Explicit application policy, including which errors become public responses.

pub struct ErrorResponses {
    pub invalid: u16
    pub missing: u16
    pub method: u16
    pub internal: u16
}

ErrorResponses.defaults

Function · Source

pub fn defaults() -> ErrorResponses

ErrorResponses.status

Function · Source

pub fn status(&self, reason: Error) -> u16

Type to search all documentation.

Keyboard shortcuts

Search documentation
Ctrl K or /
Move through results
↑ ↓
Open selected result
Enter
Close a dialog
Esc
Show these shortcuts
?