Explorar el Código

Basic query string handling.

1991
urlysses hace 7 años
padre
commit
a32c43b989
Se han modificado 2 ficheros con 21 adiciones y 3 borrados
  1. +20
    -2
      1991.fs
  2. +1
    -1
      README.md

+ 20
- 2
1991.fs Ver fichero

@@ -37,6 +37,13 @@ pubvar public
: get-public-path ( -- addr u ) : get-public-path ( -- addr u )
public 2@ ; public 2@ ;


\ Query params
pubvar queryString
: set-query-string ( addr u -- )
queryString 2! ;
: get-query-string ( -- addr u )
queryString 2@ ;

\ Request's Content-Type \ Request's Content-Type
pubvar RequestContentType pubvar RequestContentType
: set-content-type ( addr u -- ) : set-content-type ( addr u -- )
@@ -95,8 +102,19 @@ s" image/x-icon" filetype: ico
: send-response ( addr u socket -- ) : send-response ( addr u socket -- )
dup >r write-socket r> close-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 ) : file-exists? ( addr u -- addr u bool )
2dup file-status nip 0= ; 2dup file-status nip 0= ;


+ 1
- 1
README.md Ver fichero

@@ -7,7 +7,7 @@ A server-side web framework written in Forth.
+ [x] set appropriate mime-types + [x] set appropriate mime-types
+ [x] file-serving if no user-defined routes match. Search "public/" dir + [x] file-serving if no user-defined routes match. Search "public/" dir
unless otherwise specified by user. unless otherwise specified by user.
+ [ ] query arguments
+ [x] query arguments
+ [ ] PUT, POST, DELETE + [ ] PUT, POST, DELETE
+ [ ] templating + [ ] templating
+ [ ] fuzzy-/pattern-match-enabled user routes (e.g., /something/*/wildcard)? + [ ] fuzzy-/pattern-match-enabled user routes (e.g., /something/*/wildcard)?

Cargando…
Cancelar
Guardar