rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: rack-devel@googlegroups.com
Subject: [PATCH] webrick: detect partial hijack without hash headers
Date: Thu, 12 May 2016 02:31:54 +0000	[thread overview]
Message-ID: <20160512023154.GB8332@dcvr.yhbt.net> (raw)
In-Reply-To: <20160512022814.GA8332@dcvr.yhbt.net>

Response headers need not be a hash according to SPEC,
so grab the io_lambda the first time we iterate through
the headers and avoid an extra hash lookup.
---
  This is related to (but applies independently of) my lint
  clarification for case-sensitivity.

  The following changes since commit 9073125f71afd615091f575d74ec468a0b1b79bf:

    bumping version (2016-05-06 15:51:18 -0500)

  are available in the git repository at:

    git://80x24.org/rack.git webrick-header-each

  for you to fetch changes up to 2c95a6e5bc18ac860ec0f7f7614ffb4aa6ad817d:

    webrick: detect partial hijack without hash headers (2016-05-12 02:23:48 +0000)

  ----------------------------------------------------------------
  Eric Wong (1):
        webrick: detect partial hijack without hash headers

   lib/rack/handler/webrick.rb | 8 ++++----
   test/spec_webrick.rb        | 2 +-
   2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb
index 95aa892..d0fcd21 100644
--- a/lib/rack/handler/webrick.rb
+++ b/lib/rack/handler/webrick.rb
@@ -86,10 +86,11 @@ def service(req, res)
         status, headers, body = @app.call(env)
         begin
           res.status = status.to_i
+          io_lambda = nil
           headers.each { |k, vs|
-            next if k.downcase == RACK_HIJACK
-
-            if k.downcase == "set-cookie"
+            if k == RACK_HIJACK
+              io_lambda = vs
+            elsif k.downcase == "set-cookie"
               res.cookies.concat vs.split("\n")
             else
               # Since WEBrick won't accept repeated headers,
@@ -98,7 +99,6 @@ def service(req, res)
             end
           }
 
-          io_lambda = headers[RACK_HIJACK]
           if io_lambda
             rd, wr = IO.pipe
             res.body = rd
diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb
index 9ae6103..4a10c1c 100644
--- a/test/spec_webrick.rb
+++ b/test/spec_webrick.rb
@@ -171,7 +171,7 @@ def is_running?
     Rack::Lint.new(lambda{ |req|
       [
         200,
-        {"rack.hijack" => io_lambda},
+        [ [ "rack.hijack", io_lambda ] ],
         [""]
       ]
     })
-- 
EW

-- 

--- 
You received this message because you are subscribed to the Google Groups "Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2016-05-12  2:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11  5:04 rack.hijack response header check is case-insensitive? Eric Wong
2016-05-11  5:06 ` James Tucker
2016-05-12  2:28   ` [PATCH] lint: clarify "rack.hijack" case-sensitivity in response Eric Wong
2016-05-12  2:31     ` Eric Wong [this message]
2016-11-02  0:11       ` [PATCH] webrick: detect partial hijack without hash headers Eric Wong
2016-11-05  0:22         ` Aaron Patterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160512023154.GB8332@dcvr.yhbt.net \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).