hatetepe 0.5.2 → 0.6.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/.yardopts +1 -0
- data/Gemfile +9 -4
- data/Gemfile.devtools +55 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -192
- data/Rakefile +3 -2
- data/bin/hatetepe +35 -2
- data/config/devtools.yml +2 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/reek.yml +103 -0
- data/config/rubocop.yml +58 -0
- data/config/yardstick.yml +2 -0
- data/hatetepe.gemspec +23 -27
- data/lib/hatetepe/client/keep_alive.rb +59 -0
- data/lib/hatetepe/client/timeouts.rb +19 -0
- data/lib/hatetepe/client.rb +54 -302
- data/lib/hatetepe/connection/eventmachine.rb +61 -0
- data/lib/hatetepe/connection/status.rb +28 -0
- data/lib/hatetepe/errors.rb +7 -0
- data/lib/hatetepe/promise.rb +86 -0
- data/lib/hatetepe/request.rb +15 -39
- data/lib/hatetepe/response.rb +82 -22
- data/lib/hatetepe/serializer/encoding.rb +58 -0
- data/lib/hatetepe/serializer.rb +61 -0
- data/lib/hatetepe/server/keep_alive.rb +53 -13
- data/lib/hatetepe/server/timeouts.rb +17 -0
- data/lib/hatetepe/server.rb +37 -85
- data/lib/hatetepe/support/handlers.rb +19 -0
- data/lib/hatetepe/support/keep_alive.rb +14 -0
- data/lib/hatetepe/support/message.rb +40 -0
- data/lib/hatetepe/version.rb +3 -1
- data/lib/hatetepe.rb +29 -7
- data/spec/integration/error_handling_spec.rb +7 -0
- data/spec/integration/keep_alive_spec.rb +106 -0
- data/spec/integration/smoke_spec.rb +21 -0
- data/spec/integration/streaming_spec.rb +61 -0
- data/spec/integration/timeouts_spec.rb +82 -0
- data/spec/shared/integration/server_client_pair.rb +26 -0
- data/spec/spec_helper.rb +41 -10
- data/spec/support/handler.rb +55 -0
- data/spec/support/helper.rb +74 -0
- data/spec/unit/client_spec.rb +115 -156
- data/spec/unit/connection/eventmachine_spec.rb +146 -0
- data/spec/unit/request_spec.rb +35 -0
- data/spec/unit/response_spec.rb +42 -0
- data/spec/unit/server_spec.rb +65 -100
- data/spec/unit/support/keep_alive_spec.rb +52 -0
- data/spec/unit/support/message_spec.rb +41 -0
- metadata +68 -103
- data/Gemfile.lock +0 -46
- data/LICENSE +0 -19
- data/Procfile +0 -1
- data/config.ru +0 -7
- data/examples/parallel_requests.rb +0 -32
- data/lib/hatetepe/body.rb +0 -182
- data/lib/hatetepe/builder.rb +0 -171
- data/lib/hatetepe/cli.rb +0 -61
- data/lib/hatetepe/connection.rb +0 -73
- data/lib/hatetepe/events.rb +0 -35
- data/lib/hatetepe/message.rb +0 -13
- data/lib/hatetepe/parser.rb +0 -83
- data/lib/hatetepe/server/pipeline.rb +0 -20
- data/lib/hatetepe/server/rack_app.rb +0 -39
- data/lib/rack/handler/hatetepe.rb +0 -33
- data/spec/integration/cli/start_spec.rb +0 -113
- data/spec/integration/client/keep_alive_spec.rb +0 -23
- data/spec/integration/client/timeout_spec.rb +0 -97
- data/spec/integration/server/keep_alive_spec.rb +0 -27
- data/spec/integration/server/timeout_spec.rb +0 -51
- data/spec/unit/body_spec.rb +0 -205
- data/spec/unit/builder_spec.rb +0 -372
- data/spec/unit/connection_spec.rb +0 -62
- data/spec/unit/events_spec.rb +0 -96
- data/spec/unit/parser_spec.rb +0 -209
- data/spec/unit/rack_handler_spec.rb +0 -60
data/spec/unit/parser_spec.rb
DELETED
@@ -1,209 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "hatetepe/parser"
|
3
|
-
|
4
|
-
describe Hatetepe::Parser do
|
5
|
-
let(:parser) { Hatetepe::Parser.new }
|
6
|
-
|
7
|
-
context "#initialize" do
|
8
|
-
it "calls #reset" do
|
9
|
-
Hatetepe::Parser.allocate.tap {|ins|
|
10
|
-
ins.should_receive :reset
|
11
|
-
ins.__send__ :initialize
|
12
|
-
}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "#initialize {|instance| ... }" do
|
17
|
-
it "yields the new instance" do
|
18
|
-
instance = nil
|
19
|
-
Hatetepe::Parser.new {|ins|
|
20
|
-
instance = ins
|
21
|
-
}.should equal(instance)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "evals the block in its original context" do
|
25
|
-
expected, actual = nil, nil
|
26
|
-
Object.new.instance_eval {
|
27
|
-
expected = self
|
28
|
-
::Hatetepe::Parser.new {|ins|
|
29
|
-
actual = self
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
actual.should equal(expected)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "#initialize {|| ... }" do
|
38
|
-
it "evals the block in the new instance' context" do
|
39
|
-
actual = nil
|
40
|
-
expected = Hatetepe::Parser.new {
|
41
|
-
actual = self
|
42
|
-
}
|
43
|
-
|
44
|
-
actual.should equal(expected)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "#reset" do
|
49
|
-
before { parser << "GET / HTTP/1.1\r\n\r\n" }
|
50
|
-
|
51
|
-
it "resets the message" do
|
52
|
-
parser.reset
|
53
|
-
parser.message.should be_nil
|
54
|
-
end
|
55
|
-
|
56
|
-
it "resets the state to :reset" do
|
57
|
-
parser.reset
|
58
|
-
parser.reset?.should be_true
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "#<<(data)" do
|
63
|
-
it "raises a ParserError if parsing fails" do
|
64
|
-
expect {
|
65
|
-
parser << "herp derp\r\n"
|
66
|
-
}.to raise_error(Hatetepe::ParserError)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
let(:block) {
|
71
|
-
double("block").tap {|blk|
|
72
|
-
blk.stub :to_proc => proc {|*args| blk.call *args }
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
let(:do_request) {
|
77
|
-
parser << "POST / HTTP/1.1\r\n"
|
78
|
-
parser << "Transfer-Encoding: chunked\r\n"
|
79
|
-
parser << "Bar: baz\r\n"
|
80
|
-
parser << "\r\n"
|
81
|
-
parser << "6\r\n"
|
82
|
-
parser << "Hello!\r\n"
|
83
|
-
parser << "0\r\n"
|
84
|
-
parser << "\r\n"
|
85
|
-
}
|
86
|
-
|
87
|
-
let(:do_response) {
|
88
|
-
parser << "HTTP/1.1 200 OK\r\n"
|
89
|
-
parser << "\r\n"
|
90
|
-
}
|
91
|
-
|
92
|
-
context "#on_request {|request| ... }" do
|
93
|
-
it "evals the block when the request headers have arrived" do
|
94
|
-
block.should_receive(:call) {|request|
|
95
|
-
request.should equal(parser.message)
|
96
|
-
|
97
|
-
request.verb.should == "POST"
|
98
|
-
request.uri.should == "/"
|
99
|
-
request.http_version.should == "1.1"
|
100
|
-
request.headers.should == {"Transfer-Encoding" => "chunked",
|
101
|
-
"Bar" => "baz"}
|
102
|
-
}
|
103
|
-
|
104
|
-
parser.on_request &block
|
105
|
-
do_request
|
106
|
-
end
|
107
|
-
|
108
|
-
it "changes the state to :request" do
|
109
|
-
block.should_receive(:call) {
|
110
|
-
parser.request?.should be_true
|
111
|
-
}
|
112
|
-
|
113
|
-
parser.on_request &block
|
114
|
-
do_request
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "#on_response {|response| ... }" do
|
119
|
-
it "evals the block when a response line comes in" do
|
120
|
-
block.should_receive(:call) {|response|
|
121
|
-
response.should equal(parser.message)
|
122
|
-
|
123
|
-
response.status.should == 200
|
124
|
-
response.http_version.should == "1.1"
|
125
|
-
}
|
126
|
-
|
127
|
-
parser.on_response &block
|
128
|
-
do_response
|
129
|
-
end
|
130
|
-
|
131
|
-
it "changes the state to :response" do
|
132
|
-
block.should_receive(:call) {
|
133
|
-
parser.response?.should be_true
|
134
|
-
}
|
135
|
-
|
136
|
-
parser.on_response &block
|
137
|
-
do_response
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "#on_headers {|headers| ... }" do
|
142
|
-
it "evals the block when the headers are complete" do
|
143
|
-
block.should_receive(:call) {|headers|
|
144
|
-
headers.should equal(parser.message.headers)
|
145
|
-
|
146
|
-
headers["Transfer-Encoding"].should == "chunked"
|
147
|
-
headers["Bar"].should == "baz"
|
148
|
-
}
|
149
|
-
|
150
|
-
parser.on_headers &block
|
151
|
-
do_request
|
152
|
-
end
|
153
|
-
|
154
|
-
it "changes the state to :headers" do
|
155
|
-
block.should_receive(:call) {
|
156
|
-
parser.headers?.should be_true
|
157
|
-
}
|
158
|
-
|
159
|
-
parser.on_headers &block
|
160
|
-
do_request
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "#on_body {|body| ... }" do
|
165
|
-
it "evals the block when the body starts" do
|
166
|
-
block.should_receive(:call) {|body|
|
167
|
-
Fiber.new { body.read.should eq("Hello!") }.resume
|
168
|
-
}
|
169
|
-
|
170
|
-
parser.on_body &block
|
171
|
-
do_request
|
172
|
-
end
|
173
|
-
|
174
|
-
it "changes the state to :body" do
|
175
|
-
block.should_receive(:call) {
|
176
|
-
parser.body?.should be_true
|
177
|
-
}
|
178
|
-
|
179
|
-
parser.on_body &block
|
180
|
-
do_request
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
context "#on_complete { ... }" do
|
185
|
-
it "evals the block when the message is completely parsed" do
|
186
|
-
block.should_receive(:call)
|
187
|
-
|
188
|
-
parser.on_complete &block
|
189
|
-
do_request
|
190
|
-
end
|
191
|
-
|
192
|
-
it "changes the state to :complete" do
|
193
|
-
block.should_receive(:call) {
|
194
|
-
parser.complete?.should be_true
|
195
|
-
}
|
196
|
-
|
197
|
-
parser.on_complete &block
|
198
|
-
do_request
|
199
|
-
end
|
200
|
-
|
201
|
-
it "finishes the body" do
|
202
|
-
parser.on_body {|body|
|
203
|
-
body.should_receive :rewind!
|
204
|
-
body.should_receive :close_write
|
205
|
-
}
|
206
|
-
do_request
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "rack/handler/hatetepe"
|
3
|
-
|
4
|
-
describe Rack::Handler::Hatetepe do
|
5
|
-
let(:app) { double "app" }
|
6
|
-
let(:options) {
|
7
|
-
{
|
8
|
-
:Host => double("host"),
|
9
|
-
:Port => double("port")
|
10
|
-
}
|
11
|
-
}
|
12
|
-
let(:server) { double "server" }
|
13
|
-
|
14
|
-
describe ".run(app, options) {|server| ... }" do
|
15
|
-
before {
|
16
|
-
EM.stub :epoll
|
17
|
-
Signal.stub :trap
|
18
|
-
Hatetepe::Server.stub :start
|
19
|
-
}
|
20
|
-
|
21
|
-
it "starts an Hatetepe server" do
|
22
|
-
EM.should_receive :epoll
|
23
|
-
EM.should_receive(:synchrony) {|&block|
|
24
|
-
Hatetepe::Server.should_receive(:start) {|opts|
|
25
|
-
opts[:host].should equal(options[:Host])
|
26
|
-
opts[:port].should equal(options[:Port])
|
27
|
-
opts[:app].should equal(app)
|
28
|
-
}
|
29
|
-
block.call
|
30
|
-
}
|
31
|
-
Rack::Handler::Hatetepe.run app, options
|
32
|
-
end
|
33
|
-
|
34
|
-
it "can be stopped by sending SIGTERM or SIGINT" do
|
35
|
-
EM.should_receive(:synchrony) {|&block| block.call }
|
36
|
-
|
37
|
-
trapped_signals = []
|
38
|
-
Signal.should_receive(:trap).twice {|sig, &block|
|
39
|
-
trapped_signals << sig
|
40
|
-
EM.should_receive :stop
|
41
|
-
block.call
|
42
|
-
}
|
43
|
-
Rack::Handler::Hatetepe.run app
|
44
|
-
|
45
|
-
trapped_signals.should include("TERM")
|
46
|
-
trapped_signals.should include("INT")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe ".run(app) {|server| ... }" do
|
51
|
-
it "defaults Host to 0.0.0.0 and Port to 8080" do
|
52
|
-
Hatetepe::Server.should_receive(:start) {|opts|
|
53
|
-
opts[:host].should == "0.0.0.0"
|
54
|
-
opts[:port].should == 8080
|
55
|
-
EM.stop
|
56
|
-
}
|
57
|
-
Rack::Handler::Hatetepe.run app
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|