yahns Ruby server user/dev discussion
 help / color / 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	[flat|nested] only message in thread

only message in thread, back to index

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

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox