From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] http_client: do not close input on hijack
Date: Fri, 13 Mar 2015 02:27:57 +0000 [thread overview]
Message-ID: <1426213677-23569-1-git-send-email-e@80x24.org> (raw)
We probably do not want env["rack.input"] to become unusable
upon hijacking. Only drop the internal reference to it so
it can eventually become garbage-collected, but there's no
point in making env["rack.input"] unreadable.
---
lib/yahns/http_client.rb | 2 +-
test/test_rack_hijack.rb | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index 15ee9d4..1c3c8dd 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -262,7 +262,7 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
# loop. EPOLL_CTL_DEL saves about 200 bytes of unswappable kernel memory,
# so it can matter if we have lots of hijacked sockets.
self.class.queue.queue_del(self) # EPOLL_CTL_DEL
- @input = @input.close if @input
+ @input = nil # keep env["rack.input"] accessible, though
@hs = nil # no need for the HTTP parser anymore
end
diff --git a/test/test_rack_hijack.rb b/test/test_rack_hijack.rb
index 03c3051..2cc6b2d 100644
--- a/test/test_rack_hijack.rb
+++ b/test/test_rack_hijack.rb
@@ -20,6 +20,12 @@ class TestRackHijack < Testcase
HIJACK_APP = lambda { |env|
case env["PATH_INFO"]
+ when "/hijack_input"
+ io = env["rack.hijack"].call
+ env["rack.hijack_io"].write("HTTP/1.0 201 OK\r\n\r\n")
+ io.write("rack.input contents: #{env['rack.input'].read}")
+ io.close
+ return [ 500, {}, DieIfUsed.new ]
when "/hijack_req"
io = env["rack.hijack"].call
if io.respond_to?(:read_nonblock) &&
@@ -64,6 +70,14 @@ class TestRackHijack < Testcase
assert_equal 200, res.code.to_i
assert_equal "zzz", res["X-Test"]
assert_equal "1.1", res.http_version
+
+ res = Net::HTTP.start(host, port) do |h|
+ hdr = { "Content-Type" => 'application/octet-stream' }
+ h.put("/hijack_input", "BLAH", hdr)
+ end
+ assert_equal "rack.input contents: BLAH", res.body
+ assert_equal 201, res.code.to_i
+ assert_equal "1.0", res.http_version
ensure
quit_wait(pid)
end
--
EW
reply other threads:[~2015-03-13 2:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426213677-23569-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/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.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
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).