Merge branch 'master' of git://factorcode.org/git/factor

db4
Eduardo Cavazos 2007-12-11 18:01:10 -06:00
commit 0050c7bc88
3 changed files with 26 additions and 20 deletions

View File

@ -35,8 +35,9 @@ IN: webapps.file
SYMBOL: serve-file-hook
[
dupd
file-response
stdio get stream-copy
<file-reader> stdio get stream-copy
] serve-file-hook set-global
: serve-static ( filename mime-type -- )
@ -46,7 +47,6 @@ SYMBOL: serve-file-hook
"method" get "head" = [
file-response
] [
>r dup <file-reader> swap r>
serve-file-hook get call
] if
] if ;
@ -118,14 +118,6 @@ SYMBOL: page
] if ;
global [
! Serve up our own source code
"resources" [
[
"" resource-path "doc-root" set
file-responder
] with-scope
] add-simple-responder
! Serves files from a directory stored in the "doc-root"
! variable. You can set the variable in the global
! namespace, or inside the responder.

View File

@ -79,6 +79,7 @@ C: <annotation> annotation
pastebin-pastes 2dup length swap set-paste-n push ;
: submit-paste ( summary author channel mode contents -- )
2dup global [ 2array . flush ] bind
<paste> [
pastebin store get-persistent add-paste
store save-store
@ -100,7 +101,7 @@ C: <annotation> annotation
\ annotate-paste {
{ "n" v-required v-number }
{ "summary" "- no summary -" v-default }
{ "author" v-required }
{ "author" "- no author -" v-default }
{ "mode" "factor" v-default }
{ "contents" v-required }
} define-action

View File

@ -1,20 +1,33 @@
! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.files namespaces webapps.file http.server.responders
xmode.code2html kernel html ;
xmode.code2html kernel html sequences ;
IN: webapps.source
! 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/" }
[ head? ] curry* contains? ;
: source-responder ( path mime-type -- )
drop
serving-html
[ dup <file-reader> htmlize-stream ] with-html-stream ;
global [
! Serve up our own source code
"source" [
[
"" resource-path "doc-root" set
"argument" get check-source-path [
[
drop
serving-html
[ swap htmlize-stream ] with-html-stream
] serve-file-hook set
file-responder
] with-scope
"" resource-path "doc-root" set
[ source-responder ] serve-file-hook set
file-responder
] with-scope
] [
"403 forbidden" httpd-error
] if
] add-simple-responder
] bind