diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-06-30 17:15:56 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-06-30 17:20:13 -0700 |
commit | 20bf660a3efff9229c81b3b3a0feb6844bc27a7c (patch) | |
tree | 004553b916743a54361ba8ca4716d6b63d5cd73e /lib | |
parent | f01c1d4071e8ce30aa6806fd3cd8eec7491bf06c (diff) | |
download | unicorn-20bf660a3efff9229c81b3b3a0feb6844bc27a7c.tar.gz |
Support for the "Trailer:" header and associated Trailer lines should be reasonably well supported now
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn.rb | 1 | ||||
-rw-r--r-- | lib/unicorn/chunked_reader.rb | 10 | ||||
-rw-r--r-- | lib/unicorn/const.rb | 1 | ||||
-rw-r--r-- | lib/unicorn/http_request.rb | 2 |
4 files changed, 11 insertions, 3 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 343f762..6e937bf 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -13,6 +13,7 @@ module Unicorn autoload :Configurator, 'unicorn/configurator' autoload :TeeInput, 'unicorn/tee_input' autoload :ChunkedReader, 'unicorn/chunked_reader' + autoload :TrailerParser, 'unicorn/trailer_parser' autoload :Util, 'unicorn/util' Z = '' # the stock empty string we use everywhere... diff --git a/lib/unicorn/chunked_reader.rb b/lib/unicorn/chunked_reader.rb index f9bd4ec..606e4a6 100644 --- a/lib/unicorn/chunked_reader.rb +++ b/lib/unicorn/chunked_reader.rb @@ -7,8 +7,8 @@ require 'unicorn/http11' module Unicorn class ChunkedReader - def initialize(input, buf) - @input, @buf = input, buf + def initialize(env, input, buf) + @env, @input, @buf = env, input, buf @chunk_left = 0 parse_chunk_header end @@ -71,6 +71,12 @@ module Unicorn @chunk_left = $1.to_i(16) if 0 == @chunk_left # EOF buf.sub!(/\A\r\n(?:\r\n)?/, Z) # cleanup for future requests + if trailer = @env[Const::HTTP_TRAILER] + tp = TrailerParser.new(trailer) + while ! tp.execute!(@env, buf) + buf << @input.readpartial(Const::CHUNK_SIZE) + end + end @input = nil end return @chunk_left diff --git a/lib/unicorn/const.rb b/lib/unicorn/const.rb index 9dcf031..be69753 100644 --- a/lib/unicorn/const.rb +++ b/lib/unicorn/const.rb @@ -32,6 +32,7 @@ module Unicorn REMOTE_ADDR="REMOTE_ADDR".freeze HTTP_X_FORWARDED_FOR="HTTP_X_FORWARDED_FOR".freeze HTTP_EXPECT="HTTP_EXPECT".freeze + HTTP_TRAILER="HTTP_TRAILER".freeze RACK_INPUT="rack.input".freeze STREAM_INPUT="unicorn.stream_input".freeze end diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index a6ed7c9..3df9120 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -96,7 +96,7 @@ module Unicorn if te = PARAMS[Const::HTTP_TRANSFER_ENCODING] if /\Achunked\z/i =~ te - socket = ChunkedReader.new(socket, body) + socket = ChunkedReader.new(PARAMS, socket, body) length = body = nil end end |