about summary refs log tree commit homepage
path: root/Manifest
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-05 18:03:46 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-05 22:16:16 -0700
commit6945342a1f0a4caaa918f2b0b1efef88824439e0 (patch)
tree69100796a793ae26c20968ea79f24c924f362eae /Manifest
parenta48695449f49e6900819fed472f23408c62b5501 (diff)
downloadunicorn-6945342a1f0a4caaa918f2b0b1efef88824439e0.tar.gz
This adds support for handling POST/PUT request bodies sent with
chunked transfer encodings ("Transfer-Encoding: chunked").
Attention has been paid to ensure that a client cannot OOM us by
sending an extremely large chunk.

This implementation is pure Ruby as the Ragel-based
implementation in rfuzz didn't offer a streaming interface.  It
should be reasonably close to RFC-compliant but please test it
in an attempt to break it.

The more interesting part is the ability to stream data to the
hosted Rack application as it is being transferred to the
server.  This can be done regardless if the input is chunked or
not, enabling the streaming of POST/PUT bodies can allow the
hosted Rack application to process input as it receives it.  See
examples/echo.ru for an example echo server over HTTP.

Enabling streaming also allows Rack applications to support
upload progress monitoring previously supported by Mongrel
handlers.

Since Rack specifies that the input needs to be rewindable, this
input is written to a temporary file (a la tee(1)) as it is
streamed to the application the first time.  Subsequent rewinded
reads will read from the temporary file instead of the socket.

Streaming input to the application is disabled by default since
applications may not necessarily read the entire input body
before returning.  Since this is a completely new feature we've
never seen in any Ruby HTTP application server before, we're
taking the safe route by leaving it disabled by default.

Enabling this can only be done globally by changing the
Unicorn HttpRequest::DEFAULTS hash:

  Unicorn::HttpRequest::DEFAULTS["unicorn.stream_input"] = true

Similarly, a Rack application can check if streaming input
is enabled by checking the value of the "unicorn.stream_input"
key in the environment hashed passed to it.

All of this code has only been lightly tested and test coverage
is lacking at the moment.

[1] - http://tools.ietf.org/html/rfc2616#section-3.6.1
Diffstat (limited to 'Manifest')
-rw-r--r--Manifest4
1 files changed, 4 insertions, 0 deletions
diff --git a/Manifest b/Manifest
index cac021a..229572c 100644
--- a/Manifest
+++ b/Manifest
@@ -14,6 +14,7 @@ TODO
 TUNING
 bin/unicorn
 bin/unicorn_rails
+examples/echo.ru
 examples/init.sh
 ext/unicorn/http11/ext_help.h
 ext/unicorn/http11/extconf.rb
@@ -26,12 +27,14 @@ lib/unicorn/app/exec_cgi.rb
 lib/unicorn/app/old_rails.rb
 lib/unicorn/app/old_rails/static.rb
 lib/unicorn/cgi_wrapper.rb
+lib/unicorn/chunked_reader.rb
 lib/unicorn/configurator.rb
 lib/unicorn/const.rb
 lib/unicorn/http_request.rb
 lib/unicorn/http_response.rb
 lib/unicorn/launcher.rb
 lib/unicorn/socket_helper.rb
+lib/unicorn/tee_input.rb
 lib/unicorn/util.rb
 local.mk.sample
 setup.rb
@@ -120,6 +123,7 @@ test/rails/app-2.3.2.1/public/404.html
 test/rails/app-2.3.2.1/public/500.html
 test/rails/test_rails.rb
 test/test_helper.rb
+test/unit/test_chunked_reader.rb
 test/unit/test_configurator.rb
 test/unit/test_http_parser.rb
 test/unit/test_request.rb