: accept-loop ( server quot -- )
[
- >r accept r> [ with-client ] 2curry
- { log-service servers } "Client" spawn-vars
+ >r accept r> [ with-client ] 2curry "Client" spawn drop
] 2keep accept-loop ; inline
-: server-loop ( addrspec quot -- )
+: server-loop ( addrspec encoding quot -- )
>r <server> dup servers get push r>
[ accept-loop ] curry with-disposal ; inline
USING: calendar html io io.files kernel math math.parser
http.server.responders http.server.templating namespaces parser
sequences strings assocs hashtables debugger http.mime sorting
-html.elements logging ;
+html.elements logging io.encodings.binary ;
-
IN: webapps.file
+ SYMBOL: doc-root
+
: serving-path ( filename -- filename )
- "" or "doc-root" get swap path+ ;
+ "" or doc-root get swap path+ ;
: file-http-date ( filename -- string )
file-modified unix-time>timestamp timestamp>http-string ;
! The root directory is served by...
"file" set-default-responder
--] bind
++] bind
: source-responder ( path mime-type -- )
drop
serving-html
- [ dup utf8 <file-reader> htmlize-stream ] with-html-stream ;
+ [
- dup file-name swap <file-reader> htmlize-stream
++ dup file-name swap utf8 <file-reader> htmlize-stream
+ ] with-html-stream ;
global [
! Serve up our own source code