From ec14a20474575e77a23b713ee8fcda1e71b1d018 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 1 Jul 2009 13:32:33 -0700 Subject: Move "Expect: 100-continue" handling to the app This gives the app ability to deny clients with 417 instead of blindly making the decision for the underlying application. Of course, apps must be made aware of this. --- lib/unicorn.rb | 10 +++++++++- lib/unicorn/app/inetd.rb | 4 ++++ lib/unicorn/http_request.rb | 3 --- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index a2893fd..281aa7d 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -444,7 +444,15 @@ module Unicorn # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(app, client) - HttpResponse.write(client, app.call(REQUEST.read(client))) + response = app.call(env = REQUEST.read(client)) + + if 100 == response.first.to_i + client.write(Const::EXPECT_100_RESPONSE) + env.delete(Const::HTTP_EXPECT) + response = app.call(env) + end + + HttpResponse.write(client, response) # if we get any error, try to write something back to the client # assuming we haven't closed the socket, but don't get hung up # if the socket is already closed or broken. We'll always ensure diff --git a/lib/unicorn/app/inetd.rb b/lib/unicorn/app/inetd.rb index 43a23eb..c3b8bbc 100644 --- a/lib/unicorn/app/inetd.rb +++ b/lib/unicorn/app/inetd.rb @@ -97,6 +97,10 @@ module Unicorn::App end def call(env) + expect = env[Unicorn::Const::HTTP_EXPECT] and + /\A100-continue\z/i =~ expect and + return [ 100, {} , [] ] + [ 200, { 'Content-Type' => 'application/octet-stream' }, CatBody.new(env, @cmd) ] end diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 3df9120..ad1e23f 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -89,9 +89,6 @@ module Unicorn # returns a Rack environment if successful def handle_body(socket) PARAMS[Const::RACK_INPUT] = if (body = PARAMS.delete(:http_body)) - if 0 == body.size && /\A100-continue\z/i =~ PARAMS[Const::HTTP_EXPECT] - socket.write(Const::EXPECT_100_RESPONSE) - end length = PARAMS[Const::CONTENT_LENGTH].to_i if te = PARAMS[Const::HTTP_TRANSFER_ENCODING] -- cgit v1.2.3-24-ge0c7