Add routing

This commit is contained in:
Hugo Mårdbrink 2025-11-09 11:11:15 +01:00
parent 1368b7b69b
commit 4316fb2a73
7 changed files with 534 additions and 109 deletions

View file

@ -55,13 +55,14 @@ status_text :: proc(status: Status) -> string {
unmarshall_request_line :: proc(
request: ^Request,
reader: ^bufio.Reader,
allocator := context.temp_allocator
) -> RequestError {
request_line, io_err := bufio.reader_read_slice(reader, '\n')
if io_err != nil do return .InvalidRequestLine
request_line = sanitize_byte_slice(request_line)
parts := bytes.split(request_line, {' '})
parts := bytes.split(request_line, {' '}, allocator)
if len(parts) != 3 do return .InvalidRequestLine
request.method = method_from_str(string(parts[0]))
@ -86,7 +87,7 @@ unmarshall_request_headers :: proc(
header_line = sanitize_byte_slice(header_line)
if len(header_line) == 0 do break
parts := bytes.split_n(header_line, {':'}, 2)
parts := bytes.split_n(header_line, {':'}, 2, allocator)
if len(parts) != 2 do return .InvalidHeaderFormat
key := string(bytes.trim_space(parts[0]))