aboutsummaryrefslogtreecommitdiff
path: root/examples/http-server
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-31 23:33:22 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-31 23:33:22 -0400
commit5fc7577b5a3bc2c445522dfd5b287e1c6eddc3e9 (patch)
tree34d44c9330dc3ec71fc850b95b3412a1ce292cb8 /examples/http-server
parenta571ccffd795a595e990a3405dcf977aafc33c6c (diff)
Switch to using optional return values for list indexing.
Diffstat (limited to 'examples/http-server')
-rw-r--r--examples/http-server/CHANGES.md4
-rw-r--r--examples/http-server/http-server.tm12
2 files changed, 10 insertions, 6 deletions
diff --git a/examples/http-server/CHANGES.md b/examples/http-server/CHANGES.md
index 42ae752c..636f9296 100644
--- a/examples/http-server/CHANGES.md
+++ b/examples/http-server/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v1.1
+
+Version bump for Tomo syntax changes.
+
## v1.0
Initial version
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}={})