httpkit 0.6.0.pre.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +0 -2
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/README.md +32 -25
- data/Rakefile +5 -0
- data/config/flay.yml +1 -1
- data/doc/api/httpkit.html +50 -0
- data/doc/api/httpkit/body.html +149 -0
- data/doc/api/httpkit/client.html +50 -0
- data/doc/api/httpkit/client/body_handler.html +50 -0
- data/doc/api/httpkit/client/keep_alive_handler.html +79 -0
- data/doc/api/httpkit/client/mandatory_handler.html +50 -0
- data/doc/api/httpkit/client/timeouts_handler.html +82 -0
- data/doc/api/httpkit/connection/eventmachine.html +157 -0
- data/doc/api/httpkit/connection/status.html +50 -0
- data/doc/api/httpkit/promise.html +50 -0
- data/doc/api/httpkit/request.html +123 -0
- data/doc/api/httpkit/response.html +209 -0
- data/doc/api/httpkit/serializer.html +150 -0
- data/doc/api/httpkit/server.html +50 -0
- data/doc/api/httpkit/server/block_handler.html +50 -0
- data/doc/api/httpkit/server/body_handler.html +50 -0
- data/doc/api/httpkit/server/keep_alive_handler.html +145 -0
- data/doc/api/httpkit/server/mandatory_handler.html +50 -0
- data/doc/api/httpkit/server/timeouts_handler.html +81 -0
- data/doc/api/httpkit/support/handler_manager.html +95 -0
- data/doc/api/httpkit/support/message.html +50 -0
- data/doc/api/httpkit/version.html +50 -0
- data/doc/examples/echo_server.html +101 -0
- data/doc/examples/error_handling.html +176 -0
- data/doc/examples/getting_started.html +161 -0
- data/doc/examples/streaming.html +108 -0
- data/doc/index.html +165 -0
- data/examples/echo_server.rb +14 -6
- data/examples/error_handling.rb +56 -0
- data/examples/getting_started.rb +10 -18
- data/examples/streaming.rb +41 -0
- data/lib/httpkit.rb +22 -0
- data/lib/httpkit/body.rb +4 -0
- data/lib/httpkit/client.rb +1 -9
- data/lib/httpkit/client/keep_alive_handler.rb +1 -0
- data/lib/httpkit/connection/eventmachine.rb +2 -1
- data/lib/httpkit/server/block_handler.rb +13 -0
- data/lib/httpkit/server/keep_alive_handler.rb +1 -0
- data/lib/httpkit/version.rb +1 -1
- data/spec/integration/timeouts_spec.rb +3 -2
- data/spec/support/helper.rb +1 -8
- data/spec/unit/client_spec.rb +2 -21
- data/spec/unit/server_spec.rb +11 -1
- metadata +34 -5
- data/Procfile +0 -1
data/lib/httpkit.rb
CHANGED
@@ -31,6 +31,7 @@ require 'httpkit/server/body_handler'
|
|
31
31
|
require 'httpkit/server/mandatory_handler'
|
32
32
|
require 'httpkit/server/keep_alive_handler'
|
33
33
|
require 'httpkit/server/timeouts_handler'
|
34
|
+
require 'httpkit/server/block_handler'
|
34
35
|
|
35
36
|
module HTTPkit
|
36
37
|
def self.run
|
@@ -56,4 +57,25 @@ module HTTPkit
|
|
56
57
|
EM.add_timer(duration) { promise.fulfill }
|
57
58
|
promise.sync
|
58
59
|
end
|
60
|
+
|
61
|
+
def self.random_port(address)
|
62
|
+
server = TCPServer.new(address, 0)
|
63
|
+
server.addr[1]
|
64
|
+
ensure
|
65
|
+
server.shutdown if server
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.server(uri, &block)
|
69
|
+
uri = URI(uri)
|
70
|
+
Server.start(address: uri.host, port: uri.port,
|
71
|
+
handlers: [Server::KeepAliveHandler.new,
|
72
|
+
Server::TimeoutsHandler.new,
|
73
|
+
Server::BlockHandler.new(block)])
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.request(*args)
|
77
|
+
uri = URI(args[1])
|
78
|
+
client = Client.start(address: uri.host, port: uri.port)
|
79
|
+
client.request(*args)
|
80
|
+
end
|
59
81
|
end
|
data/lib/httpkit/body.rb
CHANGED
data/lib/httpkit/client.rb
CHANGED
@@ -25,12 +25,6 @@ module HTTPkit
|
|
25
25
|
Connection::EventMachine.start_client(config, self)
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.request(*args)
|
29
|
-
uri = URI(args[1])
|
30
|
-
client = start(address: uri.host, port: uri.port)
|
31
|
-
client.request(*args)
|
32
|
-
end
|
33
|
-
|
34
28
|
attr_reader :config
|
35
29
|
|
36
30
|
def initialize(config, connection)
|
@@ -60,10 +54,8 @@ module HTTPkit
|
|
60
54
|
request, served = find_request
|
61
55
|
|
62
56
|
if request
|
63
|
-
# XXX: fulfillment should happen after invoke(:receive), so that all
|
64
|
-
# handlers have run when the application code resumes
|
65
|
-
served.fulfill(response)
|
66
57
|
request, response = @handlers.invoke(:receive, request, response)
|
58
|
+
served.fulfill(response)
|
67
59
|
response.closed { finish(request) }
|
68
60
|
end
|
69
61
|
end
|
data/lib/httpkit/version.rb
CHANGED
@@ -6,7 +6,7 @@ describe HTTPkit::Client, 'in connecting state', reactor: true do
|
|
6
6
|
# connect to a non-existing host to provoke connection timeout
|
7
7
|
let(:address) { '1.2.3.4' }
|
8
8
|
let(:client_config) do
|
9
|
-
{ address: address, port:
|
9
|
+
{ address: address, port: 1234,
|
10
10
|
handlers: [HTTPkit::Client::TimeoutsHandler.new] }
|
11
11
|
end
|
12
12
|
let!(:client) { HTTPkit::Client.start(client_config) }
|
@@ -20,7 +20,8 @@ describe HTTPkit::Client, 'in connecting state', reactor: true do
|
|
20
20
|
|
21
21
|
describe 'with :connect_timeout option' do
|
22
22
|
let(:client_config) do
|
23
|
-
{ address: address, port:
|
23
|
+
{ address: address, port: 1234,
|
24
|
+
connect_timeout: 0.01,
|
24
25
|
handlers: [HTTPkit::Client::TimeoutsHandler.new] }
|
25
26
|
end
|
26
27
|
|
data/spec/support/helper.rb
CHANGED
@@ -46,18 +46,11 @@ module SpecHelper
|
|
46
46
|
'127.0.0.1'
|
47
47
|
end
|
48
48
|
|
49
|
-
def random_port
|
50
|
-
server = TCPServer.new(localhost, 0)
|
51
|
-
server.addr[1]
|
52
|
-
ensure
|
53
|
-
server.shutdown
|
54
|
-
end
|
55
|
-
|
56
49
|
def server_client_pair(server_config, client_config, interceptor)
|
57
50
|
server = nil
|
58
51
|
inspect_server(server_config, interceptor) { |_, s, _| server = s }
|
59
52
|
|
60
|
-
config = { address: localhost, port: random_port }
|
53
|
+
config = { address: localhost, port: HTTPkit.random_port(localhost) }
|
61
54
|
HTTPkit::Server.start(config.merge(server_config))
|
62
55
|
client = HTTPkit::Client.start(config.merge(client_config))
|
63
56
|
|
data/spec/unit/client_spec.rb
CHANGED
@@ -6,7 +6,8 @@ describe HTTPkit::Client do
|
|
6
6
|
let(:client) { described_class.new(config, connection) }
|
7
7
|
|
8
8
|
let(:config) do
|
9
|
-
{ address: localhost, port: random_port,
|
9
|
+
{ address: localhost, port: HTTPkit.random_port(localhost),
|
10
|
+
handlers: [handler] }
|
10
11
|
end
|
11
12
|
let(:connection) do
|
12
13
|
double('connection', :'on_message=' => nil,
|
@@ -31,26 +32,6 @@ describe HTTPkit::Client do
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
describe '.request' do
|
35
|
-
let(:arg) { double }
|
36
|
-
let(:uri) { 'http://localhost:3000' }
|
37
|
-
|
38
|
-
let(:options) { { address: 'localhost', port: 3000 } }
|
39
|
-
let(:client) { double }
|
40
|
-
let(:response) { double }
|
41
|
-
|
42
|
-
before do
|
43
|
-
allow(described_class).to receive(:start).with(options) { client }
|
44
|
-
allow(client).to receive(:request).with(arg, uri, arg, arg) { response }
|
45
|
-
end
|
46
|
-
|
47
|
-
subject { described_class.request(arg, uri, arg, arg) }
|
48
|
-
|
49
|
-
it 'starts a client and performs the request' do
|
50
|
-
expect(subject).to be(response)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
35
|
describe '#initialize' do
|
55
36
|
let(:on_message) { client.method(:receive) }
|
56
37
|
let(:teadown) { client.method(:teardown) }
|
data/spec/unit/server_spec.rb
CHANGED
@@ -6,7 +6,8 @@ describe HTTPkit::Server do
|
|
6
6
|
let(:server) { described_class.new(config, connection) }
|
7
7
|
|
8
8
|
let(:config) do
|
9
|
-
{ address: localhost, port: random_port,
|
9
|
+
{ address: localhost, port: HTTPkit.random_port(localhost),
|
10
|
+
handlers: [handler] }
|
10
11
|
end
|
11
12
|
let(:connection) do
|
12
13
|
double('connection', :'on_message=' => nil,
|
@@ -53,6 +54,13 @@ describe HTTPkit::Server do
|
|
53
54
|
.to be_a(HTTPkit::Server::BodyHandler)
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
let(:request) { double(sequence: nil) }
|
59
|
+
|
60
|
+
it 'sets up sequence numbering' do
|
61
|
+
server.serve(request)
|
62
|
+
expect(request).to have_received(:sequence).with(server, 1)
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
describe '#serve', reactor: true do
|
@@ -119,4 +127,6 @@ describe HTTPkit::Server do
|
|
119
127
|
end
|
120
128
|
|
121
129
|
describe '#setup_connection'
|
130
|
+
|
131
|
+
describe '#serve!'
|
122
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.0
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Gierth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- .yardopts
|
95
95
|
- Gemfile
|
96
96
|
- Gemfile.devtools
|
97
|
-
- Procfile
|
98
97
|
- README.md
|
99
98
|
- Rakefile
|
100
99
|
- UNLICENSE
|
@@ -105,8 +104,37 @@ files:
|
|
105
104
|
- config/reek.yml
|
106
105
|
- config/rubocop.yml
|
107
106
|
- config/yardstick.yml
|
107
|
+
- doc/api/httpkit.html
|
108
|
+
- doc/api/httpkit/body.html
|
109
|
+
- doc/api/httpkit/client.html
|
110
|
+
- doc/api/httpkit/client/body_handler.html
|
111
|
+
- doc/api/httpkit/client/keep_alive_handler.html
|
112
|
+
- doc/api/httpkit/client/mandatory_handler.html
|
113
|
+
- doc/api/httpkit/client/timeouts_handler.html
|
114
|
+
- doc/api/httpkit/connection/eventmachine.html
|
115
|
+
- doc/api/httpkit/connection/status.html
|
116
|
+
- doc/api/httpkit/promise.html
|
117
|
+
- doc/api/httpkit/request.html
|
118
|
+
- doc/api/httpkit/response.html
|
119
|
+
- doc/api/httpkit/serializer.html
|
120
|
+
- doc/api/httpkit/server.html
|
121
|
+
- doc/api/httpkit/server/block_handler.html
|
122
|
+
- doc/api/httpkit/server/body_handler.html
|
123
|
+
- doc/api/httpkit/server/keep_alive_handler.html
|
124
|
+
- doc/api/httpkit/server/mandatory_handler.html
|
125
|
+
- doc/api/httpkit/server/timeouts_handler.html
|
126
|
+
- doc/api/httpkit/support/handler_manager.html
|
127
|
+
- doc/api/httpkit/support/message.html
|
128
|
+
- doc/api/httpkit/version.html
|
129
|
+
- doc/examples/echo_server.html
|
130
|
+
- doc/examples/error_handling.html
|
131
|
+
- doc/examples/getting_started.html
|
132
|
+
- doc/examples/streaming.html
|
133
|
+
- doc/index.html
|
108
134
|
- examples/echo_server.rb
|
135
|
+
- examples/error_handling.rb
|
109
136
|
- examples/getting_started.rb
|
137
|
+
- examples/streaming.rb
|
110
138
|
- httpkit.gemspec
|
111
139
|
- lib/httpkit.rb
|
112
140
|
- lib/httpkit/body.rb
|
@@ -122,6 +150,7 @@ files:
|
|
122
150
|
- lib/httpkit/response.rb
|
123
151
|
- lib/httpkit/serializer.rb
|
124
152
|
- lib/httpkit/server.rb
|
153
|
+
- lib/httpkit/server/block_handler.rb
|
125
154
|
- lib/httpkit/server/body_handler.rb
|
126
155
|
- lib/httpkit/server/keep_alive_handler.rb
|
127
156
|
- lib/httpkit/server/mandatory_handler.rb
|
@@ -171,9 +200,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
200
|
version: '0'
|
172
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
202
|
requirements:
|
174
|
-
- - ! '
|
203
|
+
- - ! '>='
|
175
204
|
- !ruby/object:Gem::Version
|
176
|
-
version:
|
205
|
+
version: '0'
|
177
206
|
requirements: []
|
178
207
|
rubyforge_project:
|
179
208
|
rubygems_version: 2.3.0
|
data/Procfile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
web: env PORT=$PORT ADDRESS=0.0.0.0 bundle exec ruby examples/echo_server.rb
|