factor/extra/webapps/source/source.factor

34 lines
962 B
Factor
Raw Normal View History

! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.files namespaces webapps.file http.server.responders
2007-12-11 18:44:26 -05:00
xmode.code2html kernel html sequences ;
IN: webapps.source
2007-12-11 18:44:26 -05:00
! This responder is a potential security problem. Make sure you
! don't have sensitive files stored under vm/, core/, extra/
! or misc/.
: check-source-path ( path -- ? )
{ "vm/" "core/" "extra/" "misc/" }
2008-01-09 17:36:30 -05:00
[ head? ] with contains? ;
2007-12-11 18:44:26 -05:00
: source-responder ( path mime-type -- )
drop
serving-html
[ dup <file-reader> htmlize-stream ] with-html-stream ;
global [
! Serve up our own source code
"source" [
2007-12-11 18:44:26 -05:00
"argument" get check-source-path [
[
2007-12-11 18:44:26 -05:00
"" resource-path "doc-root" set
[ source-responder ] serve-file-hook set
file-responder
] with-scope
] [
"403 forbidden" httpd-error
] if
] add-simple-responder
] bind