std.http
http/1.1 client and server bits over std.net; no tls; one request per connection
HttpError
Section titled “HttpError”pub HttpError :: errors { bad_url, tls_unsupported, unknown_host, connect_failed, send_failed, recv_failed, bad_response, bad_request, too_many_redirects,}bad_url: not an http:// URL with a hosttls_unsupported: https://unknown_host: the name has no addressrecv_failed: the connection failed, or closed in the middlebad_response: what came back is not HTTP/1.xbad_request: what came in is not an HTTP requesttoo_many_redirects: more than 5
Header
Section titled “Header”pub Header :: struct { name: []const u8, value: []const u8,}name case kept as written; lookups ignore case
Response
Section titled “Response”pub Response :: struct { status: u16, reason: []const u8, headers: []const Header, body: []const u8,}Response.header
Section titled “Response.header”pub header :: fn(self: *Self, name: []const u8) -> ?[]const u8case-insensitive, first match; null if none
Request
Section titled “Request”pub Request :: struct { method: []const u8, target: []const u8, headers: []const Header, body: []const u8,}target: the path and the query: “/search?q=x”
Request.header
Section titled “Request.header”pub header :: fn(self: *Self, name: []const u8) -> ?[]const u8Request.path
Section titled “Request.path”pub path :: fn(self: *Self) -> []const u8target without the query
Request.query
Section titled “Request.query”pub query :: fn(self: *Self) -> []const u8after the ?, “” if none; parse with url::query_pairs
pub get :: fn(a: *Arena, link: []const u8) -> Response ! HttpErrorfollows redirects
request
Section titled “request”pub request :: fn(a: *Arena, method: []const u8, link: []const u8, headers: []const Header, body: []const u8) -> Response ! HttpErrorin a; up to 5 redirects (303, POST 301/302 become GET); unpacks gzip/deflate
read_request
Section titled “read_request”pub read_request :: fn(a: *Arena, conn: *net::TcpStream) -> Request ! HttpErrorrequest line, headers, body (by length or chunked), in a
reason_phrase
Section titled “reason_phrase”pub reason_phrase :: fn(status: u16) -> []const u8standard reason phrase; “Status” if unknown
respond
Section titled “respond”pub respond :: fn(conn: *net::TcpStream, status: u16, content_type: []const u8, body: []const u8) -> void ! HttpErrorwhole response: status, content type, length, Connection: close, body
respond_with
Section titled “respond_with”pub respond_with :: fn(conn: *net::TcpStream, status: u16, content_type: []const u8, headers: []const Header, body: []const u8) -> void ! HttpErrorrespond plus your own headers; .send_failed if the head exceeds 1024 bytes