spider-gazelle 2.0.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spider-gazelle.rb +12 -10
- data/lib/spider-gazelle/gazelle.rb +12 -21
- data/lib/spider-gazelle/gazelle/app_store.rb +7 -4
- data/lib/spider-gazelle/gazelle/http1.rb +64 -87
- data/lib/spider-gazelle/gazelle/request.rb +55 -62
- data/lib/spider-gazelle/logger.rb +9 -12
- data/lib/spider-gazelle/options.rb +8 -7
- data/lib/spider-gazelle/reactor.rb +11 -11
- data/lib/spider-gazelle/signaller.rb +10 -6
- data/lib/spider-gazelle/signaller/signal_parser.rb +2 -0
- data/lib/spider-gazelle/spider.rb +23 -12
- data/lib/spider-gazelle/spider/binding.rb +3 -1
- data/lib/spider-gazelle/upgrades/websocket.rb +11 -9
- data/lib/spider-gazelle/version.rb +3 -2
- data/spec/http1_spec.rb +22 -17
- data/spider-gazelle.gemspec +9 -9
- metadata +47 -51
- data/lib/rack/lock_patch.rb +0 -39
- data/spec/rack_lock_spec.rb +0 -126
data/spec/rack_lock_spec.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'rack/lint'
|
2
|
-
require 'rack/lock'
|
3
|
-
require 'rack/mock'
|
4
|
-
|
5
|
-
require 'rack/lock_patch'
|
6
|
-
|
7
|
-
|
8
|
-
module Rack
|
9
|
-
class Lock
|
10
|
-
def would_block
|
11
|
-
@count > 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
def lock_app(app)
|
18
|
-
app = Rack::Lock.new(app)
|
19
|
-
return app, Rack::Lint.new(app)
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
describe Rack::Lock do
|
24
|
-
|
25
|
-
describe 'Proxy' do
|
26
|
-
|
27
|
-
it 'delegate each' do
|
28
|
-
env = Rack::MockRequest.env_for("/")
|
29
|
-
response = Class.new {
|
30
|
-
attr_accessor :close_called
|
31
|
-
def initialize; @close_called = false; end
|
32
|
-
def each; %w{ hi mom }.each { |x| yield x }; end
|
33
|
-
}.new
|
34
|
-
|
35
|
-
app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] })[1]
|
36
|
-
response = app.call(env)[2]
|
37
|
-
list = []
|
38
|
-
response.each { |x| list << x }
|
39
|
-
expect(list).to eq(%w{ hi mom })
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'delegate to_path' do
|
43
|
-
env = Rack::MockRequest.env_for("/")
|
44
|
-
|
45
|
-
res = ['Hello World']
|
46
|
-
def res.to_path ; "/tmp/hello.txt" ; end
|
47
|
-
|
48
|
-
app = Rack::Lock.new(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, res] })
|
49
|
-
body = app.call(env)[2]
|
50
|
-
|
51
|
-
expect(body.respond_to? :to_path).to eq(true)
|
52
|
-
expect(body.to_path).to eq("/tmp/hello.txt")
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'not delegate to_path if body does not implement it' do
|
56
|
-
env = Rack::MockRequest.env_for("/")
|
57
|
-
|
58
|
-
res = ['Hello World']
|
59
|
-
|
60
|
-
app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, res] })[1]
|
61
|
-
body = app.call(env)[2]
|
62
|
-
|
63
|
-
expect(body.respond_to? :to_path).to eq(false)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'call super on close' do
|
68
|
-
env = Rack::MockRequest.env_for("/")
|
69
|
-
response = Class.new {
|
70
|
-
attr_accessor :close_called
|
71
|
-
def initialize; @close_called = false; end
|
72
|
-
def close; @close_called = true; end
|
73
|
-
}.new
|
74
|
-
|
75
|
-
app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] })[1]
|
76
|
-
app.call(env)
|
77
|
-
expect(response.close_called).to eq(false)
|
78
|
-
response.close
|
79
|
-
expect(response.close_called).to eq(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "not unlock until body is closed" do
|
83
|
-
env = Rack::MockRequest.env_for("/")
|
84
|
-
response = Object.new
|
85
|
-
lock, app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] })
|
86
|
-
|
87
|
-
expect(lock.would_block).to eq(false)
|
88
|
-
response = app.call(env)[2]
|
89
|
-
expect(lock.would_block).to eq(true)
|
90
|
-
response.close
|
91
|
-
expect(lock.would_block).to eq(false)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "return value from app" do
|
95
|
-
env = Rack::MockRequest.env_for("/")
|
96
|
-
body = [200, {"Content-Type" => "text/plain"}, %w{ hi mom }]
|
97
|
-
app = lock_app(lambda { |inner_env| body })[1]
|
98
|
-
|
99
|
-
res = app.call(env)
|
100
|
-
expect(res[0]).to eq(body[0])
|
101
|
-
expect(res[1]).to eq(body[1])
|
102
|
-
expect(res[2].to_enum.to_a).to eq(["hi", "mom"])
|
103
|
-
end
|
104
|
-
|
105
|
-
it "call synchronize on lock" do
|
106
|
-
env = Rack::MockRequest.env_for("/")
|
107
|
-
lock, app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, %w{ a b c }] })
|
108
|
-
expect(lock.would_block).to eq(false)
|
109
|
-
app.call(env)
|
110
|
-
expect(lock.would_block).to eq(true)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "unlock if the app raises" do
|
114
|
-
env = Rack::MockRequest.env_for("/")
|
115
|
-
lock, app = lock_app(lambda { raise Exception })
|
116
|
-
expect { app.call(env) }.to raise_error(Exception)
|
117
|
-
expect(lock.would_block).to eq(false)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "unlock if the app throws" do
|
121
|
-
env = Rack::MockRequest.env_for("/")
|
122
|
-
lock, app = lock_app(lambda {|_| throw :bacon })
|
123
|
-
expect { app.call(env) }.to raise_error(ArgumentError)
|
124
|
-
expect(lock.would_block).to eq(false)
|
125
|
-
end
|
126
|
-
end
|