httpserver

HTTP Server Helpers

Functions

FunctionDescription
_hsrv_byte_atInternal byte reader.
_hsrv_copyInternal: copy bytes.
_hsrv_startsInternal: check if buf at off starts with prefix of plen bytes.
_hsrv_find_bodyInternal: find double CRLF (header/body separator). Returns offset or -1.
_hsrv_write_http11Internal: write a string literal byte-by-byte. Returns new offset. Writes “HT…
_hsrv_write_crlfInternal: write CRLF. Returns new offset.
_hsrv_write_intInternal: write integer as decimal. Returns new offset. Handles values up to …
http_parse_requestParse an HTTP request. Returns handle.
http_req_methodGet method code (0=GET, 1=POST, 2=PUT, 3=DELETE, 4=PATCH, 5=HEAD).
http_req_pathCopy path to output buffer. Returns path length.
http_req_path_lenGet path length.
http_respond_okFormat a 200 OK response with body. Returns total length in out.
http_respond_404Format a 404 Not Found response. Returns total length in out.
http_status_lineFormat a status line for a given code. Returns length.

Details

_hsrv_byte_at

fn _hsrv_byte_at(buf: &i8, idx: i64) -> i64

Internal byte reader.

_hsrv_copy

fn _hsrv_copy(dst: &i8, doff: i64, src: &i8, soff: i64, len: i64) -> i64

Internal: copy bytes.

_hsrv_starts

fn _hsrv_starts(buf: &i8, off: i64, pfx: &i8, plen: i64) -> i64

Internal: check if buf at off starts with prefix of plen bytes.

_hsrv_find_body

fn _hsrv_find_body(buf: &i8, len: i64) -> i64

Internal: find double CRLF (header/body separator). Returns offset or -1.

_hsrv_write_http11

fn _hsrv_write_http11(out: &i8, pos: i64) -> i64

Internal: write a string literal byte-by-byte. Returns new offset. Writes “HTTP/1.1 " (9 bytes)

_hsrv_write_crlf

fn _hsrv_write_crlf(out: &i8, pos: i64) -> i64

Internal: write CRLF. Returns new offset.

_hsrv_write_int

fn _hsrv_write_int(out: &i8, pos: i64, val: i64) -> i64

Internal: write integer as decimal. Returns new offset. Handles values up to 99999 without alloc_pages.

http_parse_request

fn http_parse_request(buf: &i8, len: i64) -> &i64

Parse an HTTP request. Returns handle.

http_req_method

fn http_req_method(h: &i64) -> i64

Get method code (0=GET, 1=POST, 2=PUT, 3=DELETE, 4=PATCH, 5=HEAD).

http_req_path

fn http_req_path(h: &i64, out: &i8) -> i64

Copy path to output buffer. Returns path length.

http_req_path_len

fn http_req_path_len(h: &i64) -> i64

Get path length.

http_respond_ok

fn http_respond_ok(body: &i8, blen: i64, out: &i8) -> i64

Format a 200 OK response with body. Returns total length in out.

http_respond_404

fn http_respond_404(out: &i8) -> i64

Format a 404 Not Found response. Returns total length in out.

http_status_line

fn http_status_line(code: i64, out: &i8) -> i64

Format a status line for a given code. Returns length.