Hi… I am well aware that this diff view is very suboptimal. It will be fixed when the refactored server comes along!
Add license headers
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
use htmpl;
use io;
use net::http;
use net::uri;
use strings;
export fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nomem | uri::invalid) = {
htmpl::write(conn, "HTTP/1.1 200 OK\r\n")?;
htmpl::write(conn, "Content-Type: text/html\r\n\r\n")?;
let segments = segments_from_path(request.target.raw_path)?;
defer strings::freeall(segments);
tp_index(conn, segments)?;
};
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
use strings;
use net::uri;
// The result must be freed with strings::freeall;
fn segments_from_path(s: str) ([]str | nomem | net::uri::invalid) = {
let sp: []str = strings::split(s, "/")?;
for (let i = 1z; i < len(sp); i += 1)
sp[i - 1] = net::uri::percent_decode(sp[i])?;
return sp[.. len(sp) - 1];
};