servers>> random addr>> port>>
] with-scope "port" set ;
+: add-port ( url -- url' )
+ >url clone "port" get >>port ;
+
+: stop-test-httpd ( -- )
+ "http://localhost/quit" add-port http-get nip
+ "Goodbye" assert= ;
+
[ ] [
<dispatcher>
add-quit-action
test-httpd
] unit-test
-: add-port ( url -- url' )
- >url clone "port" get >>port ;
-
[ t ] [
"vocab:http/test/foo.html" ascii file-contents
"http://localhost/nested/foo.html" add-port http-get nip =
[ ] [
- [ "http://localhost/quit" add-port http-get 2drop ] ignore-errors
+ [ stop-test-httpd ] ignore-errors
] unit-test
! Dispatcher bugs
"vocab:http/test/foo.html" ascii file-contents =
] unit-test
-[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test
+[ ] [ stop-test-httpd ] unit-test
! Check behavior of 307 redirect (reported by Chris Double)
[ ] [
] with-directory
] must-fail
-[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test
+[ ] [ stop-test-httpd ] unit-test
+
+! Check that index.fhtml works
+[ ] [
+ <dispatcher>
+ "resource:basis/http/test/" <static> enable-fhtml >>default
+ add-quit-action
+ test-httpd
+] unit-test
+
+[ "OK\n\n" ] [ "http://localhost/" add-port http-get nip ] unit-test
+
+[ ] [ stop-test-httpd ] unit-test
fry xml.entities destructors urls html xml.syntax\r
html.templates.fhtml http http.server http.server.responses\r
http.server.redirection xml.writer ;\r
+FROM: sets => adjoin ;\r
IN: http.server.static\r
\r
-TUPLE: file-responder root hook special allow-listings ;\r
+TUPLE: file-responder root hook special index-names allow-listings ;\r
\r
: modified-since ( request -- date )\r
"if-modified-since" header ";" split1 drop\r
file-responder new\r
swap >>hook\r
swap >>root\r
- H{ } clone >>special ;\r
+ H{ } clone >>special\r
+ V{ "index.html" } >>index-names ;\r
\r
: (serve-static) ( path mime-type -- response )\r
[\r
] if ;\r
\r
: find-index ( filename -- path )\r
- "index.html" append-path dup exists? [ drop f ] unless ;\r
+ file-responder get index-names>>\r
+ [ append-path dup exists? [ drop f ] unless ] with map-find\r
+ drop ;\r
\r
: serve-directory ( filename -- response )\r
url get path>> "/" tail? [\r
".." over member?\r
[ drop <400> ] [ "/" join serve-object ] if ;\r
\r
-! file responder integration\r
+: add-index ( name responder -- )\r
+ index-names>> adjoin ;\r
+\r
+: serve-fhtml ( path -- response )\r
+ <fhtml> "text/html" <content> ;\r
+\r
: enable-fhtml ( responder -- responder )\r
- [ <fhtml> "text/html" <content> ]\r
- "application/x-factor-server-page"\r
- pick special>> set-at ;\r
+ [ serve-fhtml ] "application/x-factor-server-page" pick special>> set-at\r
+ "index.fhtml" over add-index ;\r