Better HTTPD logging, and fix a file-responder bug
parent
e9f73af344
commit
802681fa1e
|
@ -32,12 +32,12 @@ parser sequences strings ;
|
|||
"method" get "head" = [
|
||||
drop
|
||||
] [
|
||||
"request" get [ directory. ] simple-html-document
|
||||
"request" get [ dup log-message directory. ] simple-html-document
|
||||
] if ;
|
||||
|
||||
: serve-directory ( filename -- )
|
||||
"/" ?tail [
|
||||
dup "/index.html" append dup exists? [
|
||||
"/" over tail? [
|
||||
dup "index.html" append dup exists? [
|
||||
nip serve-file
|
||||
] [
|
||||
drop list-directory
|
||||
|
|
|
@ -62,10 +62,10 @@ SYMBOL: responders
|
|||
"Content-Length" swap hash dup
|
||||
[ string>number read query>hash ] when ;
|
||||
|
||||
: log-user-agent ( hash -- )
|
||||
"User-Agent" swap hash [
|
||||
[ "User Agent: " % ": " % % ] "" make log-message
|
||||
] when* ;
|
||||
: log-headers ( hash -- )
|
||||
[
|
||||
drop { "User-Agent" "X-Forwarded-For" "Host" } member?
|
||||
] hash-subset [ ": " swap append3 log-message ] hash-each ;
|
||||
|
||||
: prepare-url ( url -- url )
|
||||
#! This is executed in the with-request namespace.
|
||||
|
@ -75,7 +75,7 @@ SYMBOL: responders
|
|||
|
||||
: prepare-header ( -- )
|
||||
read-header dup "header" set
|
||||
dup log-user-agent
|
||||
dup log-headers
|
||||
read-post-request "response" set ;
|
||||
|
||||
! Responders are called in a new namespace with these
|
||||
|
|
Loading…
Reference in New Issue