Skip to content

Commit

Permalink
added parser for byte-ranges, added trace facility work flow state-ma…
Browse files Browse the repository at this point in the history
…chine
  • Loading branch information
x6j8x committed Aug 1, 2010
1 parent 41b2f3b commit 4db6624
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 140 deletions.
12 changes: 8 additions & 4 deletions machine/data/data.factor
@@ -1,6 +1,7 @@
USING: accessors arrays assocs byte-arrays calendar uuid
USING: accessors arrays assocs byte-arrays calendar
calendar.format combinators combinators.short-circuit
io.encodings.utf8 kernel math namespaces quotations ;
io.encodings.utf8 kernel linked-assocs math namespaces
quotations uuid ;
IN: http.machine.data

TUPLE: stream-body chunk next ;
Expand Down Expand Up @@ -35,12 +36,12 @@ TUPLE: machine-response
content-type
content-charset
content-encoding
body ;
body
size ;

: <machine-response> ( -- response )
machine-response new
"1.1" >>version
500 >>code
H{ } clone >>headers
V{ } clone >>cookies
utf8 >>content-encoding ;
Expand Down Expand Up @@ -74,6 +75,9 @@ TUPLE: machine-response
: set-response-header ( value key -- )
response headers>> set-at ; inline

: append-response-header ( value key -- )
response headers>> push-at ; inline

: get-response-header ( header -- value )
response headers>> at ; inline

Expand Down
2 changes: 1 addition & 1 deletion machine/dispatch/dispatch.factor
Expand Up @@ -66,7 +66,7 @@ TUPLE: dispatch-tree value children ;
hosts>> { [ [ host>> ] [ ] bi* at ] [ [ drop "*" ] [ ] bi* at ] } 2|| ;

: create-bindings ( rest bindings assoc -- rest' assoc )
2over { [ nip empty? not ] [ drop empty? not ] } 2&&
2over { [ nip { [ empty? not ] [ "*" = not ] } 1&& ] [ drop empty? not ] } 2&&
[
[ 2unclip-slice ] dip [ set-at ] keep create-bindings
] [ nip ] if ;
Expand Down
11 changes: 10 additions & 1 deletion machine/example/example.factor
@@ -1,10 +1,12 @@
USING: accessors fry http.machine http.machine.data
http.machine.dispatch http.machine.resource
io.servers.connection kernel namespaces threads ;
http.machine.resource.static io io.servers.connection kernel
math.parser namespaces threads ;
IN: http.machine.example

SINGLETON: example-resource


<PRIVATE

: produce-text-content ( -- content )
Expand All @@ -23,10 +25,17 @@ M: example-resource content-types-provided
! M: example-resource allowed-methods
! drop { "POST" "PUT" "OPTIONS" } ;

M: example-resource process-post drop
"content-length" get-request-header [
string>number request body>> stream-read drop
] when* t ;

M: example-resource resource-exists? drop t ;

: start-machine-example ( -- )
<machine-dispatcher>
#{ "*" "example" "*" } example-resource add-rule
#{ "*" "files" "*" } "/Users/sascha/Temp/" <static-file-resource> add-rule
<machine> 8080 >>insecure
[ machine-server set-global ]
[ '[ _ start-server ] in-thread ] bi ;
Expand Down

0 comments on commit 4db6624

Please sign in to comment.