summary refs log tree commit
path: root/lib/rack/handler/cgi.rb
diff options
context:
space:
mode:
authorRyan Tomayko <rtomayko@gmail.com>2009-03-05 21:21:52 -0800
committerRyan Tomayko <rtomayko@gmail.com>2009-03-12 16:18:33 -0700
commitc82590723025c7f51c2bfa246225263d1971f179 (patch)
treef4120cf7e15660f90a7c2c014786bc13d5529fed /lib/rack/handler/cgi.rb
parent86ddc7a6ec68d7b6951c2dbd07947c4254e8bc0d (diff)
downloadrack-c82590723025c7f51c2bfa246225263d1971f179.tar.gz
Handlers use ContentLength and Chunked middleware where needed
Each Rack handler now automatically wraps the app in one or more
pieces of middleware based on how the server is implemented. All
handlers use the Rack::ContentLength middleware and some handlers
use the Rack::Chunked middleware. Handlers that don't use the
Chunked middleware either do not require CE for some reason or
implement CE at the server level.

* The Thin handler uses Chunked and ContentLength middleware. Thin
  has built-in CE support but also allows the app to apply it
  explicitly. Using our middleware for consistency and also because
  I believe the Thin folks want to remove CE support in the future.

* The Mongrel handler uses Chunked and ContentLength middleware.
  Mongrel has built-in CE support but also allows the app to apply
  it explicitly. Using our middleware for consistency across
  handlers.

* The SCGI handler uses Chunked and ContentLength middleware.

* The WEBrick handler uses ContentLength middleware only; WEBrick
  has a really touchy CE implementation that doesn't like it when
  CE is applied by the application.

* The FastCGI handler uses ContentLength only. FastCGI has its own
  mechanism for transferring bodies that do not include an
  explicit Content-Length. The FastCGI server applies the chunked
  encoding if needed.

* The CGI handler uses ContentLength only. The CGI spec forbids the
  use of the Transfer-Encoding header in output from CGI programs.
  The server program is responsible for applying the chunked
  encoding if needed. Closing stdout signals the end of the body
  so it's not really needed anyway.

* The LSWS handler uses ContentLength middleware only. Like CGI, LSWS
  closes the stream after transfer so chunked encoding is never
  required.
Diffstat (limited to 'lib/rack/handler/cgi.rb')
-rw-r--r--lib/rack/handler/cgi.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/rack/handler/cgi.rb b/lib/rack/handler/cgi.rb
index f2c976cf..e38156c7 100644
--- a/lib/rack/handler/cgi.rb
+++ b/lib/rack/handler/cgi.rb
@@ -1,3 +1,5 @@
+require 'rack/content_length'
+
 module Rack
   module Handler
     class CGI
@@ -6,6 +8,8 @@ module Rack
       end
 
       def self.serve(app)
+        app = ContentLength.new(app)
+
         env = ENV.to_hash
         env.delete "HTTP_CONTENT_LENGTH"