diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-15 16:54:24 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-15 16:54:24 +0800 |
commit | cf33db77f0bea4e458107e134b23798594e0127a (patch) | |
tree | d59b0ff6f2ff55c64ac46bcc2ef5c5122eaf5944 /req.ha | |
parent | Use HAREFLAGS (diff) | |
download | forge-cf33db77f0bea4e458107e134b23798594e0127a.tar.gz forge-cf33db77f0bea4e458107e134b23798594e0127a.tar.zst forge-cf33db77f0bea4e458107e134b23798594e0127a.zip |
Handle invalid URIs by reporting back to the user
Diffstat (limited to '')
-rw-r--r-- | req.ha | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -9,8 +9,19 @@ use net::uri; use strconv; use strings; -fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nomem | uri::invalid) = { - let segments = segments_from_path(request.target.raw_path)?; +fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nomem) = { + let segments = match(segments_from_path(request.target.raw_path)) { + case let s: []str => + yield s; + case uri::invalid => + start_response(conn, 400, "text/plain")?; + fmt::fprintln(conn, "Invalid URI")?; + return void; + case nomem => + return nomem; + case => + abort("unreachable"); + }; defer strings::freeall(segments); let trailing_slash: bool = false; |