yahns 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,18 +8,14 @@ class TestRackHijack < Testcase
8
8
  alias setup server_helper_setup
9
9
  alias teardown server_helper_teardown
10
10
 
11
- class DieIfUsed
12
- def each
13
- abort "body.each called after response hijack\n"
14
- end
15
-
16
- def close
17
- abort "body.close called after response hijack\n"
18
- end
19
- end
20
-
21
11
  HIJACK_APP = lambda { |env|
22
12
  case env["PATH_INFO"]
13
+ when "/hijack_input"
14
+ io = env["rack.hijack"].call
15
+ env["rack.hijack_io"].write("HTTP/1.0 201 OK\r\n\r\n")
16
+ io.write("rack.input contents: #{env['rack.input'].read}")
17
+ io.close
18
+ return [ 500, {}, DieIfUsed.new ]
23
19
  when "/hijack_req"
24
20
  io = env["rack.hijack"].call
25
21
  if io.respond_to?(:read_nonblock) &&
@@ -64,6 +60,14 @@ class TestRackHijack < Testcase
64
60
  assert_equal 200, res.code.to_i
65
61
  assert_equal "zzz", res["X-Test"]
66
62
  assert_equal "1.1", res.http_version
63
+
64
+ res = Net::HTTP.start(host, port) do |h|
65
+ hdr = { "Content-Type" => 'application/octet-stream' }
66
+ h.put("/hijack_input", "BLAH", hdr)
67
+ end
68
+ assert_equal "rack.input contents: BLAH", res.body
69
+ assert_equal 201, res.code.to_i
70
+ assert_equal "1.0", res.http_version
67
71
  ensure
68
72
  quit_wait(pid)
69
73
  end
data/test/test_server.rb CHANGED
@@ -815,7 +815,7 @@ class TestServer < Testcase
815
815
  GTL.synchronize { app(:rack, ru) { listen "#{host}:#{port}" } }
816
816
  logger(Logger.new(err.path))
817
817
  end
818
- mkserver(cfg, @srv) do
818
+ pid = mkserver(cfg, @srv) do
819
819
  s2.autoclose = false
820
820
  ENV["YAHNS_FD"] = "#{@srv.fileno},#{s2.fileno}"
821
821
  end
@@ -842,5 +842,7 @@ class TestServer < Testcase
842
842
  assert_nil a2.read(1)
843
843
  a2.close
844
844
  s2.close
845
+ ensure
846
+ quit_wait(pid)
845
847
  end
846
848
  end
data/test/test_ssl.rb CHANGED
@@ -71,6 +71,15 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
71
71
  end
72
72
  end
73
73
  client = ssl_client(host, port)
74
+ client.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
75
+ buf = ''
76
+ Timeout.timeout(60) do
77
+ buf << client.readpartial(111) until buf =~ /HI\z/
78
+ end
79
+ head, body = buf.split("\r\n\r\n", 2)
80
+ assert_equal "HI", body
81
+ assert_match %r{\AHTTP/1\.\d 200 OK\r\n}, head
82
+
74
83
  client.write("GET / HTTP/1.0\r\n\r\n")
75
84
  head, body = client.read.split("\r\n\r\n", 2)
76
85
  assert_equal "HI", body
@@ -79,4 +88,67 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
79
88
  client.close if client
80
89
  quit_wait(pid)
81
90
  end
91
+
92
+ def test_ssl_hijack
93
+ err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
94
+ ctx = srv_ctx
95
+ pid = mkserver(cfg) do
96
+ cfg.instance_eval do
97
+ ru = lambda do |env|
98
+ io = env['rack.hijack'].call
99
+ Thread.new(io) do |s|
100
+ s.write "HTTP/1.1 201 Switching Protocols\r\n\r\n"
101
+ case req = s.gets
102
+ when "inspect\n"
103
+ s.puts(s.instance_variable_get(:@ssl).inspect)
104
+ when "remote_address\n"
105
+ s.puts(s.remote_address.inspect)
106
+ when "each\n"
107
+ line = ''
108
+ s.each do |l|
109
+ l.strip!
110
+ line << l
111
+ break if l == 'd'
112
+ end
113
+ s.puts line
114
+ when "missing\n"
115
+ begin
116
+ s.any_old_invalid_test_method
117
+ s.puts "FAIL"
118
+ rescue => e
119
+ s.puts "#{e.class}: #{e.message}"
120
+ end
121
+ when nil
122
+ s.close
123
+ else
124
+ p [ :ERR, req ]
125
+ end until s.closed?
126
+ end
127
+ [ 200, DieIfUsed, DieIfUsed ]
128
+ end
129
+ app(:rack, ru) { listen "#{host}:#{port}", ssl_ctx: ctx }
130
+ logger(Logger.new(err.path))
131
+ end
132
+ end
133
+ client = ssl_client(host, port)
134
+ client.write("GET / HTTP/1.0\r\n\r\n")
135
+
136
+ Timeout.timeout(60) do
137
+ assert_equal "HTTP/1.1 201 Switching Protocols\r\n", client.gets
138
+ assert_equal "\r\n", client.gets
139
+ client.puts "inspect"
140
+ assert_match %r{SSLSocket}, client.gets
141
+ client.puts "remote_address"
142
+ assert_equal client.to_io.local_address.inspect, client.gets.strip
143
+ client.puts "missing"
144
+ assert_match %r{NoMethodError}, client.gets
145
+
146
+ client.puts "each"
147
+ %w(a b c d).each { |x| client.puts(x) }
148
+ assert_equal "abcd", client.gets.strip
149
+ end
150
+ ensure
151
+ client.close if client
152
+ quit_wait(pid)
153
+ end
82
154
  end if defined?(OpenSSL)
@@ -0,0 +1,20 @@
1
+ # -*- encoding: binary -*-
2
+ # Copyright (C) 2009-2015 all contributors <yahns-public@yhbt.net>
3
+ # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
4
+ require_relative 'helper'
5
+
6
+ class TestTmpIO < Testcase
7
+ def test_writev
8
+ a, b = UNIXSocket.pair
9
+ a.extend Kgio::PipeMethods
10
+ tmpio = Yahns::TmpIO.new(Dir.tmpdir)
11
+ ary = [ "hello\n".freeze, "world\n".freeze ].freeze
12
+ tmpio.kgio_trywritev(ary)
13
+ a.trysendfile(tmpio, 0, 12)
14
+ assert_equal "hello\nworld\n", b.read(12)
15
+ ensure
16
+ b.close
17
+ a.close
18
+ tmpio.close
19
+ end
20
+ end
data/test/test_wbuf.rb CHANGED
@@ -19,7 +19,8 @@ class TestWbuf < Testcase
19
19
  buf = "*" * (16384 * 2)
20
20
  nr = 1000
21
21
  [ true, false ].each do |persist|
22
- wbuf = Yahns::Wbuf.new([], persist, Dir.tmpdir)
22
+ wbuf = Yahns::Wbuf.new([], persist, Dir.tmpdir, :wait_writable)
23
+ assert_equal :wait_writable, wbuf.busy
23
24
  a, b = socketpair
24
25
  assert_nil wbuf.wbuf_write(a, "HIHI")
25
26
  assert_equal "HIHI", b.read(4)
@@ -69,7 +70,7 @@ class TestWbuf < Testcase
69
70
  break
70
71
  end while true
71
72
  end
72
- wbuf = Yahns::Wbuf.new([], true, Dir.tmpdir)
73
+ wbuf = Yahns::Wbuf.new([], true, Dir.tmpdir, :wait_writable)
73
74
  assert_equal :wait_writable, wbuf.wbuf_write(a, buf)
74
75
  assert_equal :wait_writable, wbuf.wbuf_flush(a)
75
76
 
@@ -93,7 +94,7 @@ class TestWbuf < Testcase
93
94
  def test_wbuf_flush_close
94
95
  pipe = cloexec_pipe
95
96
  persist = true
96
- wbuf = Yahns::Wbuf.new(pipe[0], persist, Dir.tmpdir)
97
+ wbuf = Yahns::Wbuf.new(pipe[0], persist, Dir.tmpdir, :wait_writable)
97
98
  refute wbuf.respond_to?(:close) # we don't want this for HttpResponse body
98
99
  sp = socketpair
99
100
  rv = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yahns hackers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio
@@ -138,6 +138,8 @@ files:
138
138
  - lib/yahns/max_body/wrapper.rb
139
139
  - lib/yahns/openssl_client.rb
140
140
  - lib/yahns/openssl_server.rb
141
+ - lib/yahns/proxy_http_response.rb
142
+ - lib/yahns/proxy_pass.rb
141
143
  - lib/yahns/queue.rb
142
144
  - lib/yahns/queue_egg.rb
143
145
  - lib/yahns/queue_epoll.rb
@@ -185,6 +187,7 @@ files:
185
187
  - test/test_input.rb
186
188
  - test/test_mt_accept.rb
187
189
  - test/test_output_buffering.rb
190
+ - test/test_proxy_pass.rb
188
191
  - test/test_rack.rb
189
192
  - test/test_rack_hijack.rb
190
193
  - test/test_reopen_logs.rb
@@ -193,6 +196,7 @@ files:
193
196
  - test/test_server.rb
194
197
  - test/test_ssl.rb
195
198
  - test/test_stream_file.rb
199
+ - test/test_tmpio.rb
196
200
  - test/test_unix_socket.rb
197
201
  - test/test_wbuf.rb
198
202
  - yahns.gemspec