1
0
mirror of https://github.com/urlysses/1991.git synced 2024-11-15 17:18:04 -05:00

Basic query string handling.

This commit is contained in:
urlysses 2017-02-17 09:10:06 -05:00
parent 888cf5ba77
commit a32c43b989
2 changed files with 21 additions and 3 deletions

22
1991.fs
View File

@ -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= ;

View File

@ -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)?