From a32c43b989110ab0e3e9b2f30477f35fafe8de3c Mon Sep 17 00:00:00 2001 From: urlysses Date: Fri, 17 Feb 2017 09:10:06 -0500 Subject: [PATCH] Basic query string handling. --- 1991.fs | 22 ++++++++++++++++++++-- README.md | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/1991.fs b/1991.fs index a08cbdb..c428131 100644 --- a/1991.fs +++ b/1991.fs @@ -37,6 +37,13 @@ pubvar public : get-public-path ( -- addr u ) public 2@ ; +\ Query params +pubvar queryString +: set-query-string ( addr u -- ) + queryString 2! ; +: get-query-string ( -- addr u ) + queryString 2@ ; + \ Request's Content-Type pubvar RequestContentType : set-content-type ( addr u -- ) @@ -95,8 +102,19 @@ s" image/x-icon" filetype: ico : send-response ( addr u socket -- ) dup >r write-socket r> close-socket ; -: requested-route ( addr u -- routeaddr routeu ) - bl scan 1- swap 1+ swap 2dup bl scan swap drop - ; +: store-query-string ( addr u -- raddr ru ) + 2dup s" ?" search if + 2dup set-query-string \ store query string + swap drop - + else + s" " set-query-string \ store empty query string (reset) + 2drop + then ; + +: requested-route ( addr u -- raddr ru ) + bl scan 1- swap 1+ swap + 2dup bl scan swap drop - \ get the space-separated route + store-query-string ; \ strip and store the query, leave route : file-exists? ( addr u -- addr u bool ) 2dup file-status nip 0= ; diff --git a/README.md b/README.md index 3a202b7..f145e2b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A server-side web framework written in Forth. + [x] set appropriate mime-types + [x] file-serving if no user-defined routes match. Search "public/" dir unless otherwise specified by user. -+ [ ] query arguments ++ [x] query arguments + [ ] PUT, POST, DELETE + [ ] templating + [ ] fuzzy-/pattern-match-enabled user routes (e.g., /something/*/wildcard)?