yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
* [PUSHED] http_response: support rack.hijack on HTTP/0.9 responses
@ 2016-11-29 21:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-11-29 21:05 UTC (permalink / raw)
  To: yahns-public

We still need to iterate through all response headers to support
response-only Rack hijacking.  Previously, we only supported
full hijacking on so-called "HTTP/0.9" clients.

n.b. This diff will be easier to read with the
     -b/--ignore-space-change option of git-diff(1) or GNU diff(1)
---
 lib/yahns/http_response.rb | 114 ++++++++++++++++++++++-----------------------
 test/test_rack_hijack.rb   |   6 +++
 2 files changed, 62 insertions(+), 58 deletions(-)

diff -b --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index e2fc940..a31ab70 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -131,7 +131,6 @@ def http_response_write(res, opt)
     term = false
     hdr_only, chunk_ok = opt
 
-    if @hs.headers?
     code = status.to_i
     hdr_only ||= Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(code)
     msg = Rack::Utils::HTTP_STATUS_CODES[code]
@@ -191,8 +190,7 @@ def http_response_write(res, opt)
       else
         response_wait_write(rv) or return :close
       end
-      end while true
-    end
+    end while @hs.headers?
 
     return response_hijacked(hijack) if hijack
     return http_response_done(alive) if hdr_only
diff --git a/test/test_rack_hijack.rb b/test/test_rack_hijack.rb
index 671387e..c878552 100644
--- a/test/test_rack_hijack.rb
+++ b/test/test_rack_hijack.rb
@@ -86,6 +86,12 @@ def test_hijack
     assert_equal "rack.input contents: BLAH", res.body
     assert_equal 201, res.code.to_i
     assert_equal "1.0", res.http_version
+
+    # ancient "HTTP/0.9"
+    c = get_tcp_client(host, port)
+    c.write("GET /hijack_res\r\n\r\n")
+    res = Timeout.timeout(30) { c.read }
+    assert_equal 'response.hijacked', res
   ensure
     quit_wait(pid)
   end
-- 
EW

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-11-29 21:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-29 21:05 [PUSHED] http_response: support rack.hijack on HTTP/0.9 responses Eric Wong

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).