unicorn 3.0.0pre2 → 3.0.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.
- data/GIT-VERSION-GEN +1 -1
- data/lib/unicorn/const.rb +2 -2
- data/lib/unicorn/stream_input.rb +14 -25
- data/script/isolate_for_tests +1 -1
- data/test/unit/test_stream_input.rb +44 -0
- data/test/unit/test_tee_input.rb +8 -0
- metadata +9 -11
data/GIT-VERSION-GEN
CHANGED
data/lib/unicorn/const.rb
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
# improve things much compared to constants.
|
8
8
|
module Unicorn::Const
|
9
9
|
|
10
|
-
# The current version of Unicorn, currently 3.0.
|
11
|
-
UNICORN_VERSION = "3.0.
|
10
|
+
# The current version of Unicorn, currently 3.0.0
|
11
|
+
UNICORN_VERSION = "3.0.0"
|
12
12
|
|
13
13
|
# default TCP listen host address (0.0.0.0, all interfaces)
|
14
14
|
DEFAULT_HOST = "0.0.0.0"
|
data/lib/unicorn/stream_input.rb
CHANGED
@@ -39,28 +39,25 @@ class Unicorn::StreamInput
|
|
39
39
|
# ios.read(length [, buffer]) will return immediately if there is
|
40
40
|
# any data and only block when nothing is available (providing
|
41
41
|
# IO#readpartial semantics).
|
42
|
-
def read(
|
43
|
-
length
|
44
|
-
rv = args.shift || ''
|
45
|
-
if length.nil?
|
46
|
-
read_all(rv)
|
47
|
-
else
|
42
|
+
def read(length = nil, rv = '')
|
43
|
+
if length
|
48
44
|
if length <= @rbuf.size
|
49
|
-
|
50
|
-
|
45
|
+
length < 0 and raise ArgumentError, "negative length #{length} given"
|
46
|
+
rv.replace(@rbuf.slice!(0, length))
|
51
47
|
else
|
52
|
-
|
53
|
-
|
54
|
-
@
|
55
|
-
|
56
|
-
@socket.kgio_read(length, @buf) or eof!
|
48
|
+
to_read = length - @rbuf.size
|
49
|
+
rv.replace(@rbuf.slice!(0, @rbuf.size))
|
50
|
+
until to_read == 0 || eof? || (rv.size > 0 && @chunked)
|
51
|
+
@socket.kgio_read(to_read, @buf) or eof!
|
57
52
|
filter_body(@rbuf, @buf)
|
58
53
|
rv << @rbuf
|
59
|
-
|
60
|
-
@rbuf.replace('')
|
54
|
+
to_read -= @rbuf.size
|
61
55
|
end
|
56
|
+
@rbuf.replace('')
|
62
57
|
end
|
63
58
|
rv = nil if rv.empty? && length != 0
|
59
|
+
else
|
60
|
+
read_all(rv)
|
64
61
|
end
|
65
62
|
rv
|
66
63
|
end
|
@@ -83,16 +80,8 @@ class Unicorn::StreamInput
|
|
83
80
|
re = /\A(.*?#{Regexp.escape(sep)})/
|
84
81
|
|
85
82
|
begin
|
86
|
-
@rbuf.
|
87
|
-
if eof?
|
88
|
-
if @rbuf.empty?
|
89
|
-
return nil
|
90
|
-
else
|
91
|
-
rv = @rbuf.dup
|
92
|
-
@rbuf.replace('')
|
93
|
-
return rv
|
94
|
-
end
|
95
|
-
end
|
83
|
+
@rbuf.sub!(re, '') and return $1
|
84
|
+
return @rbuf.empty? ? nil : @rbuf.slice!(0, @rbuf.size) if eof?
|
96
85
|
@socket.kgio_read(@@io_chunk_size, @buf) or eof!
|
97
86
|
filter_body(once = '', @buf)
|
98
87
|
@rbuf << once
|
data/script/isolate_for_tests
CHANGED
@@ -21,6 +21,13 @@ class TestStreamInput < Test::Unit::TestCase
|
|
21
21
|
Process.waitall
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_read_negative
|
25
|
+
r = init_request('hello')
|
26
|
+
si = Unicorn::StreamInput.new(@rd, r)
|
27
|
+
assert_raises(ArgumentError) { si.read(-1) }
|
28
|
+
assert_equal 'hello', si.read
|
29
|
+
end
|
30
|
+
|
24
31
|
def test_read_small
|
25
32
|
r = init_request('hello')
|
26
33
|
si = Unicorn::StreamInput.new(@rd, r)
|
@@ -146,6 +153,43 @@ class TestStreamInput < Test::Unit::TestCase
|
|
146
153
|
assert_equal '', rv
|
147
154
|
end
|
148
155
|
|
156
|
+
def test_gets_read_mix
|
157
|
+
r = init_request("hello\nasdfasdf")
|
158
|
+
si = Unicorn::StreamInput.new(@rd, r)
|
159
|
+
assert_equal "hello\n", si.gets
|
160
|
+
assert_equal "asdfasdf", si.read(9)
|
161
|
+
assert_nil si.read(9)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_gets_read_mix_chunked
|
165
|
+
r = @parser = Unicorn::HttpParser.new
|
166
|
+
body = "6\r\nhello"
|
167
|
+
@buf = "POST / HTTP/1.1\r\n" \
|
168
|
+
"Host: localhost\r\n" \
|
169
|
+
"Transfer-Encoding: chunked\r\n" \
|
170
|
+
"\r\n#{body}"
|
171
|
+
assert_equal @env, @parser.headers(@env, @buf)
|
172
|
+
assert_equal body, @buf
|
173
|
+
si = Unicorn::StreamInput.new(@rd, r)
|
174
|
+
@wr.syswrite "\n\r\n"
|
175
|
+
assert_equal "hello\n", si.gets
|
176
|
+
@wr.syswrite "8\r\nasdfasdf\r\n"
|
177
|
+
assert_equal"asdfasdf", si.read(9) + si.read(9)
|
178
|
+
@wr.syswrite "0\r\n\r\n"
|
179
|
+
assert_nil si.read(9)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_gets_read_mix_big
|
183
|
+
r = init_request("hello\n#{'.' * 65536}")
|
184
|
+
si = Unicorn::StreamInput.new(@rd, r)
|
185
|
+
assert_equal "hello\n", si.gets
|
186
|
+
assert_equal '.' * 16384, si.read(16384)
|
187
|
+
assert_equal '.' * 16383, si.read(16383)
|
188
|
+
assert_equal '.' * 16384, si.read(16384)
|
189
|
+
assert_equal '.' * 16385, si.read(16385)
|
190
|
+
assert_nil si.gets
|
191
|
+
end
|
192
|
+
|
149
193
|
def init_request(body, size = nil)
|
150
194
|
@parser = Unicorn::HttpParser.new
|
151
195
|
body = body.to_s.freeze
|
data/test/unit/test_tee_input.rb
CHANGED
@@ -267,6 +267,14 @@ class TestTeeInput < Test::Unit::TestCase
|
|
267
267
|
assert_equal "World", @env['HTTP_HELLO']
|
268
268
|
end
|
269
269
|
|
270
|
+
def test_gets_read_mix
|
271
|
+
r = init_request("hello\nasdfasdf")
|
272
|
+
ti = Unicorn::TeeInput.new(@rd, r)
|
273
|
+
assert_equal "hello\n", ti.gets
|
274
|
+
assert_equal "asdfasdf", ti.read(9)
|
275
|
+
assert_nil ti.read(9)
|
276
|
+
end
|
277
|
+
|
270
278
|
private
|
271
279
|
|
272
280
|
def init_request(body, size = nil)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 7
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 0
|
10
|
+
version: 3.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Unicorn hackers
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-20 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -375,14 +375,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
375
375
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
376
376
|
none: false
|
377
377
|
requirements:
|
378
|
-
- - "
|
378
|
+
- - ">="
|
379
379
|
- !ruby/object:Gem::Version
|
380
|
-
hash:
|
380
|
+
hash: 3
|
381
381
|
segments:
|
382
|
-
-
|
383
|
-
|
384
|
-
- 1
|
385
|
-
version: 1.3.1
|
382
|
+
- 0
|
383
|
+
version: "0"
|
386
384
|
requirements: []
|
387
385
|
|
388
386
|
rubyforge_project: mongrel
|