Merge branch 'master' of git://factorcode.org/git/factor
commit
b6e5bac483
|
@ -45,10 +45,13 @@ ERROR: no-boundary ;
|
||||||
";" split1 nip
|
";" split1 nip
|
||||||
"=" split1 nip [ no-boundary ] unless* ;
|
"=" split1 nip [ no-boundary ] unless* ;
|
||||||
|
|
||||||
|
SYMBOL: upload-limit
|
||||||
|
|
||||||
: read-multipart-data ( request -- mime-parts )
|
: read-multipart-data ( request -- mime-parts )
|
||||||
[ "content-type" header ]
|
[ "content-type" header ]
|
||||||
[ "content-length" header string>number ] bi
|
[ "content-length" header string>number ] bi
|
||||||
unlimit-input
|
unlimited-input
|
||||||
|
upload-limit get stream-throws limit-input
|
||||||
stream-eofs limit-input
|
stream-eofs limit-input
|
||||||
binary decode-input
|
binary decode-input
|
||||||
parse-multipart-form-data parse-multipart ;
|
parse-multipart-form-data parse-multipart ;
|
||||||
|
@ -252,10 +255,13 @@ LOG: httpd-benchmark DEBUG
|
||||||
|
|
||||||
TUPLE: http-server < threaded-server ;
|
TUPLE: http-server < threaded-server ;
|
||||||
|
|
||||||
|
SYMBOL: request-limit
|
||||||
|
|
||||||
|
64 1024 * request-limit set-global
|
||||||
|
|
||||||
M: http-server handle-client*
|
M: http-server handle-client*
|
||||||
drop
|
drop [
|
||||||
[
|
request-limit get stream-throws limit-input
|
||||||
64 1024 * stream-throws limit-input
|
|
||||||
?refresh-all
|
?refresh-all
|
||||||
[ read-request ] ?benchmark
|
[ read-request ] ?benchmark
|
||||||
[ do-request ] ?benchmark
|
[ do-request ] ?benchmark
|
||||||
|
|
|
@ -5,14 +5,14 @@ IN: io.streams.limited
|
||||||
|
|
||||||
HELP: <limited-stream>
|
HELP: <limited-stream>
|
||||||
{ $values
|
{ $values
|
||||||
{ "stream" "an input stream" } { "limit" integer } { "mode" "a " { $link limited-stream } " mode singleton" }
|
{ "stream" "an input stream" } { "limit" integer } { "mode" { $link stream-throws } " or " { $link stream-eofs } }
|
||||||
{ "stream'" "an input stream" }
|
{ "stream'" "an input stream" }
|
||||||
}
|
}
|
||||||
{ $description "Constructs a new " { $link limited-stream } " from an existing stream. User code should use " { $link limit } " or " { $link limit-input } "." } ;
|
{ $description "Constructs a new " { $link limited-stream } " from an existing stream. User code should use " { $link limit } " or " { $link limit-input } "." } ;
|
||||||
|
|
||||||
HELP: limit
|
HELP: limit
|
||||||
{ $values
|
{ $values
|
||||||
{ "stream" "an input stream" } { "limit" integer } { "mode" "a " { $link limited-stream } " mode singleton" }
|
{ "stream" "an input stream" } { "limit" integer } { "mode" { $link stream-throws } " or " { $link stream-eofs } }
|
||||||
{ "stream'" "a stream" }
|
{ "stream'" "a stream" }
|
||||||
}
|
}
|
||||||
{ $description "Changes a decoder's stream to be a limited stream, or wraps " { $snippet "stream" } " in a " { $link limited-stream } "." }
|
{ $description "Changes a decoder's stream to be a limited stream, or wraps " { $snippet "stream" } " in a " { $link limited-stream } "." }
|
||||||
|
@ -36,7 +36,7 @@ HELP: limit
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: unlimit
|
HELP: unlimited
|
||||||
{ $values
|
{ $values
|
||||||
{ "stream" "an input stream" }
|
{ "stream" "an input stream" }
|
||||||
{ "stream'" "a stream" }
|
{ "stream'" "a stream" }
|
||||||
|
@ -51,22 +51,22 @@ HELP: limited-stream
|
||||||
|
|
||||||
HELP: limit-input
|
HELP: limit-input
|
||||||
{ $values
|
{ $values
|
||||||
{ "limit" integer } { "mode" "a " { $link limited-stream } " mode singleton" }
|
{ "limit" integer } { "mode" { $link stream-throws } " or " { $link stream-eofs } }
|
||||||
}
|
}
|
||||||
{ $description "Wraps the current " { $link input-stream } " in a " { $link limited-stream } "." } ;
|
{ $description "Wraps the current " { $link input-stream } " in a " { $link limited-stream } "." } ;
|
||||||
|
|
||||||
HELP: unlimit-input
|
HELP: unlimited-input
|
||||||
{ $description "Returns the underlying stream of the limited-stream stored in " { $link input-stream } "." } ;
|
{ $description "Returns the underlying stream of the limited-stream stored in " { $link input-stream } "." } ;
|
||||||
|
|
||||||
HELP: stream-eofs
|
HELP: stream-eofs
|
||||||
{ $values
|
{ $values
|
||||||
{ "value" "a " { $link limited-stream } " mode singleton" }
|
{ "value" { $link stream-throws } " or " { $link stream-eofs } }
|
||||||
}
|
}
|
||||||
{ $description "If the " { $slot "mode" } " of a limited stream is set to this singleton, the stream will return " { $link f } " upon exhaustion." } ;
|
{ $description "If the " { $slot "mode" } " of a limited stream is set to this singleton, the stream will return " { $link f } " upon exhaustion." } ;
|
||||||
|
|
||||||
HELP: stream-throws
|
HELP: stream-throws
|
||||||
{ $values
|
{ $values
|
||||||
{ "value" "a " { $link limited-stream } " mode singleton" }
|
{ "value" { $link stream-throws } " or " { $link stream-eofs } }
|
||||||
}
|
}
|
||||||
{ $description "If the " { $slot "mode" } " of a limited stream is set to this singleton, the stream will throw " { $link limit-exceeded } " upon exhaustion." } ;
|
{ $description "If the " { $slot "mode" } " of a limited stream is set to this singleton, the stream will throw " { $link limit-exceeded } " upon exhaustion." } ;
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ ARTICLE: "io.streams.limited" "Limited input streams"
|
||||||
"Wrap the current " { $link input-stream } " in a limited stream:"
|
"Wrap the current " { $link input-stream } " in a limited stream:"
|
||||||
{ $subsection limit-input }
|
{ $subsection limit-input }
|
||||||
"Unlimits a limited stream:"
|
"Unlimits a limited stream:"
|
||||||
{ $subsection unlimit }
|
{ $subsection unlimited }
|
||||||
"Unlimits the current " { $link input-stream } ":"
|
"Unlimits the current " { $link input-stream } ":"
|
||||||
{ $subsection unlimit-input }
|
{ $subsection unlimited-input }
|
||||||
"Make a limited stream throw an exception on exhaustion:"
|
"Make a limited stream throw an exception on exhaustion:"
|
||||||
{ $subsection stream-throws }
|
{ $subsection stream-throws }
|
||||||
"Make a limited stream return " { $link f } " on exhaustion:"
|
"Make a limited stream return " { $link f } " on exhaustion:"
|
||||||
|
|
|
@ -57,13 +57,13 @@ IN: io.streams.limited.tests
|
||||||
|
|
||||||
[ t ]
|
[ t ]
|
||||||
[
|
[
|
||||||
"abc" <string-reader> 3 stream-eofs limit unlimit
|
"abc" <string-reader> 3 stream-eofs limit unlimited
|
||||||
"abc" <string-reader> =
|
"abc" <string-reader> =
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ]
|
[ t ]
|
||||||
[
|
[
|
||||||
"abc" <string-reader> 3 stream-eofs limit unlimit
|
"abc" <string-reader> 3 stream-eofs limit unlimited
|
||||||
"abc" <string-reader> =
|
"abc" <string-reader> =
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ IN: io.streams.limited.tests
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
"resource:license.txt" utf8 <file-reader> &dispose
|
"resource:license.txt" utf8 <file-reader> &dispose
|
||||||
3 stream-eofs limit unlimit
|
3 stream-eofs limit unlimited
|
||||||
"resource:license.txt" utf8 <file-reader> &dispose
|
"resource:license.txt" utf8 <file-reader> &dispose
|
||||||
[ decoder? ] both?
|
[ decoder? ] both?
|
||||||
] with-destructors
|
] with-destructors
|
||||||
|
|
|
@ -24,20 +24,20 @@ M: decoder limit ( stream limit mode -- stream' )
|
||||||
M: object limit ( stream limit mode -- stream' )
|
M: object limit ( stream limit mode -- stream' )
|
||||||
<limited-stream> ;
|
<limited-stream> ;
|
||||||
|
|
||||||
GENERIC: unlimit ( stream -- stream' )
|
GENERIC: unlimited ( stream -- stream' )
|
||||||
|
|
||||||
M: decoder unlimit ( stream -- stream' )
|
M: decoder unlimited ( stream -- stream' )
|
||||||
[ stream>> ] change-stream ;
|
[ stream>> ] change-stream ;
|
||||||
|
|
||||||
M: object unlimit ( stream -- stream' )
|
M: object unlimited ( stream -- stream' )
|
||||||
stream>> stream>> ;
|
stream>> stream>> ;
|
||||||
|
|
||||||
: limit-input ( limit mode -- ) input-stream [ -rot limit ] change ;
|
: limit-input ( limit mode -- ) input-stream [ -rot limit ] change ;
|
||||||
|
|
||||||
: unlimit-input ( -- ) input-stream [ unlimit ] change ;
|
: unlimited-input ( -- ) input-stream [ unlimited ] change ;
|
||||||
|
|
||||||
: with-unlimited-stream ( stream quot -- )
|
: with-unlimited-stream ( stream quot -- )
|
||||||
[ clone unlimit ] dip call ; inline
|
[ clone unlimited ] dip call ; inline
|
||||||
|
|
||||||
: with-limited-stream ( stream limit mode quot -- )
|
: with-limited-stream ( stream limit mode quot -- )
|
||||||
[ limit ] dip call ; inline
|
[ limit ] dip call ; inline
|
||||||
|
|
Loading…
Reference in New Issue