From 4b26ff6a95d0754a2aa38caeb7b309cd83e4052b Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@slava-pestovs-macbook-pro.local>
Date: Fri, 20 Mar 2009 01:47:09 -0500
Subject: [PATCH 1/2] Add variables to set request-limit and upload-limit

---
 basis/http/server/server.factor               | 16 +++++++++++-----
 basis/io/streams/limited/limited-docs.factor  | 18 +++++++++---------
 basis/io/streams/limited/limited-tests.factor |  6 +++---
 basis/io/streams/limited/limited.factor       | 10 +++++-----
 4 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/basis/http/server/server.factor b/basis/http/server/server.factor
index d7f6f1841a..1e16b4146c 100755
--- a/basis/http/server/server.factor
+++ b/basis/http/server/server.factor
@@ -45,10 +45,13 @@ ERROR: no-boundary ;
     ";" split1 nip
     "=" split1 nip [ no-boundary ] unless* ;
 
+SYMBOL: upload-limit
+
 : read-multipart-data ( request -- mime-parts )
     [ "content-type" header ]
     [ "content-length" header string>number ] bi
-    unlimit-input
+    unlimited-input
+    upload-limit get stream-throws limit-input
     stream-eofs limit-input
     binary decode-input
     parse-multipart-form-data parse-multipart ;
@@ -250,12 +253,15 @@ LOG: httpd-benchmark DEBUG
         httpd-benchmark
     ] [ call ] if ; inline
 
-TUPLE: http-server < threaded-server ;
+TUPLE: http-server < threaded-server request-limit ;
+
+SYMBOL: request-limit
+
+64 1024 * request-limit set-global
 
 M: http-server handle-client*
-    drop
-    [
-        64 1024 * stream-throws limit-input
+    drop [
+        request-limit get stream-throws limit-input
         ?refresh-all
         [ read-request ] ?benchmark
         [ do-request ] ?benchmark
diff --git a/basis/io/streams/limited/limited-docs.factor b/basis/io/streams/limited/limited-docs.factor
index fac1232cc0..130c7ba3a9 100755
--- a/basis/io/streams/limited/limited-docs.factor
+++ b/basis/io/streams/limited/limited-docs.factor
@@ -5,14 +5,14 @@ IN: io.streams.limited
 
 HELP: <limited-stream>
 { $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" }
 }
 { $description "Constructs a new " { $link limited-stream } " from an existing stream. User code should use " { $link limit } " or " { $link limit-input } "." } ;
 
 HELP: limit
 { $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" }
 }
 { $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
      { "stream" "an input stream" }
      { "stream'" "a stream" }
@@ -51,22 +51,22 @@ HELP: limited-stream
 
 HELP: limit-input
 { $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 } "." } ;
 
-HELP: unlimit-input
+HELP: unlimited-input
 { $description "Returns the underlying stream of the limited-stream stored in " { $link input-stream } "." } ;
 
 HELP: stream-eofs
 { $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." } ;
 
 HELP: stream-throws
 { $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." } ;
 
@@ -79,9 +79,9 @@ ARTICLE: "io.streams.limited" "Limited input streams"
 "Wrap the current " { $link input-stream } " in a limited stream:"
 { $subsection limit-input }
 "Unlimits a limited stream:"
-{ $subsection unlimit }
+{ $subsection unlimited }
 "Unlimits the current " { $link input-stream } ":"
-{ $subsection unlimit-input }
+{ $subsection unlimited-input }
 "Make a limited stream throw an exception on exhaustion:"
 { $subsection stream-throws }
 "Make a limited stream return " { $link f } " on exhaustion:"
diff --git a/basis/io/streams/limited/limited-tests.factor b/basis/io/streams/limited/limited-tests.factor
index feddc130e9..36c257fb5e 100644
--- a/basis/io/streams/limited/limited-tests.factor
+++ b/basis/io/streams/limited/limited-tests.factor
@@ -57,13 +57,13 @@ IN: io.streams.limited.tests
 
 [ t ]
 [
-    "abc" <string-reader> 3 stream-eofs limit unlimit
+    "abc" <string-reader> 3 stream-eofs limit unlimited
     "abc" <string-reader> =
 ] unit-test
 
 [ t ]
 [
-    "abc" <string-reader> 3 stream-eofs limit unlimit
+    "abc" <string-reader> 3 stream-eofs limit unlimited
     "abc" <string-reader> =
 ] unit-test
 
@@ -71,7 +71,7 @@ IN: io.streams.limited.tests
 [
     [
         "resource:license.txt" utf8 <file-reader> &dispose
-        3 stream-eofs limit unlimit
+        3 stream-eofs limit unlimited
         "resource:license.txt" utf8 <file-reader> &dispose
         [ decoder? ] both?
     ] with-destructors
diff --git a/basis/io/streams/limited/limited.factor b/basis/io/streams/limited/limited.factor
index 1237b3aba2..fe3dd9ad93 100755
--- a/basis/io/streams/limited/limited.factor
+++ b/basis/io/streams/limited/limited.factor
@@ -24,20 +24,20 @@ M: decoder limit ( stream limit mode -- stream' )
 M: object limit ( stream limit mode -- stream' )
     <limited-stream> ;
 
-GENERIC: unlimit ( stream -- stream' )
+GENERIC: unlimited ( stream -- stream' )
 
-M: decoder unlimit ( stream -- stream' )
+M: decoder unlimited ( stream -- stream' )
     [ stream>> ] change-stream ;
 
-M: object unlimit ( stream -- stream' )
+M: object unlimited ( stream -- stream' )
     stream>> stream>> ;
 
 : 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 -- )
-    [ clone unlimit ] dip call ; inline
+    [ clone unlimited ] dip call ; inline
 
 : with-limited-stream ( stream limit mode quot -- )
     [ limit ] dip call ; inline

From fd0fd8fb7146ab3e948460fca53f4f45442e80d3 Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@slava-pestovs-macbook-pro.local>
Date: Fri, 20 Mar 2009 01:53:49 -0500
Subject: [PATCH 2/2] Remove useless slot

---
 basis/http/server/server.factor | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/basis/http/server/server.factor b/basis/http/server/server.factor
index 1e16b4146c..8b22b9a885 100755
--- a/basis/http/server/server.factor
+++ b/basis/http/server/server.factor
@@ -253,7 +253,7 @@ LOG: httpd-benchmark DEBUG
         httpd-benchmark
     ] [ call ] if ; inline
 
-TUPLE: http-server < threaded-server request-limit ;
+TUPLE: http-server < threaded-server ;
 
 SYMBOL: request-limit