diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 23:33:22 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 23:33:22 -0400 |
| commit | 5fc7577b5a3bc2c445522dfd5b287e1c6eddc3e9 (patch) | |
| tree | 34d44c9330dc3ec71fc850b95b3412a1ce292cb8 /examples/http-server/http-server.tm | |
| parent | a571ccffd795a595e990a3405dcf977aafc33c6c (diff) | |
Switch to using optional return values for list indexing.
Diffstat (limited to 'examples/http-server/http-server.tm')
| -rw-r--r-- | examples/http-server/http-server.tm | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/http-server/http-server.tm b/examples/http-server/http-server.tm index 8e8aff7e..cc99b521 100644 --- a/examples/http-server/http-server.tm +++ b/examples/http-server/http-server.tm @@ -74,12 +74,12 @@ func serve(port:Int32, handler:func(request:HTTPRequest -> HTTPResponse), num_th struct HTTPRequest(method:Text, path:Text, version:Text, headers:[Text], body:Text) func from_text(text:Text -> HTTPRequest?) m := text.pattern_captures($Pat'{word} {..} HTTP/{..}{crlf}{..}') or return none - method := m[1] - path := m[2].replace_pattern($Pat'{2+ /}', '/') - version := m[3] - rest := m[-1].pattern_captures($Pat/{..}{2 crlf}{0+ ..}/) or return none - headers := rest[1].split_pattern($Pat/{crlf}/) - body := rest[-1] + method := m[1]! + path := m[2]!.replace_pattern($Pat'{2+ /}', '/') + version := m[3]! + rest := m[-1]!.pattern_captures($Pat/{..}{2 crlf}{0+ ..}/) or return none + headers := rest[1]!.split_pattern($Pat/{crlf}/) + body := rest[-1]! return HTTPRequest(method, path, version, headers, body) struct HTTPResponse(body:Text, status=200, content_type="text/plain", headers:{Text=Text}={}) |
