goliath 0.9.2 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of goliath might be problematic. Click here for more details.
- data/Gemfile +1 -1
- data/{HISTORY → HISTORY.md} +26 -12
- data/README.md +17 -10
- data/examples/api_proxy.rb +28 -0
- data/examples/async_aroundware_demo.rb +14 -10
- data/examples/auth_and_rate_limit.rb +160 -38
- data/examples/config/auth_and_rate_limit.rb +8 -5
- data/examples/config/content_stream.rb +5 -9
- data/examples/early_abort.rb +37 -0
- data/examples/env_use_statements.rb +3 -0
- data/examples/favicon.rb +40 -0
- data/examples/http_log.rb +2 -1
- data/examples/public/favicon.ico +0 -0
- data/examples/rack_routes.rb +19 -0
- data/examples/rasterize/rasterize.rb +2 -1
- data/examples/rasterize/rasterize_and_shorten.rb +10 -5
- data/goliath.gemspec +7 -9
- data/lib/goliath/api.rb +16 -4
- data/lib/goliath/connection.rb +8 -7
- data/lib/goliath/deprecated/async_aroundware.rb +133 -0
- data/lib/goliath/{synchrony → deprecated}/mongo_receiver.rb +28 -8
- data/lib/goliath/deprecated/response_receiver.rb +97 -0
- data/lib/goliath/env.rb +5 -0
- data/lib/goliath/rack.rb +6 -1
- data/lib/goliath/rack/async_middleware.rb +34 -12
- data/lib/goliath/rack/barrier_aroundware.rb +228 -0
- data/lib/goliath/rack/barrier_aroundware_factory.rb +60 -0
- data/lib/goliath/rack/builder.rb +22 -6
- data/lib/goliath/rack/heartbeat.rb +8 -5
- data/lib/goliath/rack/simple_aroundware.rb +114 -0
- data/lib/goliath/rack/simple_aroundware_factory.rb +121 -0
- data/lib/goliath/rack/validation/required_param.rb +9 -2
- data/lib/goliath/request.rb +7 -0
- data/lib/goliath/runner.rb +17 -5
- data/lib/goliath/server.rb +11 -3
- data/lib/goliath/test_helper.rb +14 -14
- data/lib/goliath/version.rb +1 -1
- data/spec/integration/early_abort_spec.rb +50 -0
- data/spec/integration/keepalive_spec.rb +2 -2
- data/spec/integration/pipelining_spec.rb +2 -2
- data/spec/integration/rack_routes_spec.rb +25 -0
- data/spec/integration/template_spec.rb +2 -0
- data/spec/unit/rack/heartbeat_spec.rb +11 -1
- data/spec/unit/rack/validation/required_param_spec.rb +10 -0
- data/spec/unit/runner_spec.rb +13 -0
- data/spec/unit/server_spec.rb +4 -0
- metadata +218 -265
- data/lib/goliath/rack/async_aroundware.rb +0 -56
- data/lib/goliath/synchrony/response_receiver.rb +0 -64
@@ -1,56 +0,0 @@
|
|
1
|
-
module Goliath
|
2
|
-
module Rack
|
3
|
-
class AsyncAroundware
|
4
|
-
# Create a new AsyncAroundware
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# class MyResponseReceiver < Goliath::Rack::MultiReceiver
|
8
|
-
# # ... define pre_process and post_process ...
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# class AsyncAroundwareDemoMulti < Goliath::API
|
12
|
-
# use Goliath::Rack::AsyncAroundware, MyResponseReceiver
|
13
|
-
# # ... stuff ...
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# @param app [#call] the downstream app
|
17
|
-
# @param response_receiver_klass a class that quacks like a
|
18
|
-
# Goliath::Rack::ResponseReceiver and an EM::Deferrable
|
19
|
-
# @param *args [Array] extra args to pass to the response_receiver
|
20
|
-
def initialize app, response_receiver_klass, *args
|
21
|
-
@app = app
|
22
|
-
@response_receiver_klass = response_receiver_klass
|
23
|
-
@response_receiver_args = args
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
def call(env)
|
28
|
-
response_receiver = new_response_receiver(env)
|
29
|
-
|
30
|
-
# put response_receiver in the middle of the async_callback chain:
|
31
|
-
# * save the old callback chain;
|
32
|
-
# * put the response_receiver in as the new async_callback;
|
33
|
-
# * when the response_receiver completes, invoke the old callback chain
|
34
|
-
async_callback = env['async.callback']
|
35
|
-
env['async.callback'] = response_receiver
|
36
|
-
response_receiver.callback{ do_postprocess(env, async_callback, response_receiver) }
|
37
|
-
response_receiver.errback{ do_postprocess(env, async_callback, response_receiver) }
|
38
|
-
|
39
|
-
response_receiver.pre_process
|
40
|
-
|
41
|
-
response_receiver.call(@app.call(env))
|
42
|
-
end
|
43
|
-
|
44
|
-
def new_response_receiver(env)
|
45
|
-
@response_receiver_klass.new(env, *@response_receiver_args)
|
46
|
-
end
|
47
|
-
|
48
|
-
include Goliath::Rack::Validator
|
49
|
-
def do_postprocess(env, async_callback, response_receiver)
|
50
|
-
Goliath::Rack::Validator.safely(env) do
|
51
|
-
async_callback.call(response_receiver.post_process)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Goliath
|
2
|
-
module Synchrony
|
3
|
-
|
4
|
-
#
|
5
|
-
# FIXME: generalize this to work with any deferrable
|
6
|
-
module ResponseReceiver
|
7
|
-
attr_accessor :env, :status, :headers, :body
|
8
|
-
|
9
|
-
# Override this method in your middleware to perform any preprocessing
|
10
|
-
# (launching a deferred request, perhaps)
|
11
|
-
def pre_process
|
12
|
-
end
|
13
|
-
|
14
|
-
# Override this method in your middleware to perform any postprocessing. This
|
15
|
-
# will only be invoked when the deferrable and the response have been
|
16
|
-
# received.
|
17
|
-
#
|
18
|
-
# @return [Array] array contains [status, headers, body]
|
19
|
-
def post_process
|
20
|
-
[status, headers, body]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Invoked by the async_callback chain. Stores the [status, headers, body]
|
24
|
-
# for post_process'ing
|
25
|
-
def call shb
|
26
|
-
return shb if shb.first == Goliath::Connection::AsyncResponse.first
|
27
|
-
@status, @headers, @body = shb
|
28
|
-
succeed if finished?
|
29
|
-
end
|
30
|
-
|
31
|
-
# Have we received a response?
|
32
|
-
def response_received?
|
33
|
-
!! @status
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class MultiReceiver < EM::Synchrony::Multi
|
38
|
-
include ResponseReceiver
|
39
|
-
|
40
|
-
# Create a new MultiReceiver
|
41
|
-
# @param env [Goliath::Env] the current environment
|
42
|
-
def initialize env
|
43
|
-
@env = env
|
44
|
-
super()
|
45
|
-
end
|
46
|
-
|
47
|
-
alias_method :enqueue, :add
|
48
|
-
|
49
|
-
def successes
|
50
|
-
responses[:callback]
|
51
|
-
end
|
52
|
-
|
53
|
-
def failures
|
54
|
-
responses[:errback]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Finished if we received a response and the multi request is finished
|
58
|
-
def finished?
|
59
|
-
super && response_received?
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|