after_response 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/after_response.gemspec +5 -4
- data/lib/after_response.rb +40 -7
- data/rails/init.rb +0 -2
- metadata +7 -7
data/after_response.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "after_response"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.9"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "Provides hooks to execute callbacks after the response has been delivered to the client."
|
6
6
|
|
7
7
|
s.description = <<-EOF
|
8
|
-
AfterResponse provides callbacks into the Passenger2
|
8
|
+
AfterResponse provides callbacks into the Passenger2.2, Passenger3 and Unicorn
|
9
9
|
request cycle. The main goal is to delay as much non-critical processing until later, delivering
|
10
|
-
the response to the client application sooner. This would mainly include logging data into a
|
11
|
-
service, sending email and other tasks that do not affect the response body in any way.
|
10
|
+
the response to the client application sooner. This would mainly include logging data into a Observatory-like
|
11
|
+
event logging service, sending email and other tasks that do not affect the response body in any way.
|
12
12
|
EOF
|
13
13
|
|
14
14
|
s.files = Dir['{lib/*,rails/*}'] +
|
@@ -21,3 +21,4 @@ EOF
|
|
21
21
|
s.homepage = 'https://github.com/kevn/after_response'
|
22
22
|
|
23
23
|
end
|
24
|
+
|
data/lib/after_response.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'after_response/callbacks'
|
1
3
|
|
2
4
|
module AfterResponse
|
3
5
|
|
@@ -9,28 +11,59 @@ module AfterResponse
|
|
9
11
|
),
|
10
12
|
OpenStruct.new(
|
11
13
|
:name => :passenger2,
|
12
|
-
|
13
|
-
:
|
14
|
-
|
14
|
+
# This has only been tested on 2.2.14 and 2.2.15. Other 2.2.x might work if the main_loop method is unchanged.
|
15
|
+
:test => lambda{ defined?(PhusionPassenger) && ['2.2.14', '2.2.15'].include?(PhusionPassenger::VERSION_STRING) },
|
16
|
+
:lib => 'after_response/adapters/passenger2_2'
|
17
|
+
),
|
18
|
+
OpenStruct.new(
|
19
|
+
:name => :unicorn_middleware,
|
20
|
+
:test => lambda{ defined?(Unicorn) },
|
21
|
+
:lib => 'after_response/adapters/unicorn_middleware'
|
22
|
+
),
|
23
|
+
# FIXME: Find a better way to inspect the installed Rack middleware for the above and fallback
|
24
|
+
# to monkeypatch if middleware isn't installed.
|
25
|
+
# OpenStruct.new(
|
26
|
+
# :name => :unicorn_monkeypatch,
|
27
|
+
# :test => lambda{ defined?(Unicorn) },
|
28
|
+
# :lib => 'after_response/adapters/unicorn_monkeypatch'
|
29
|
+
# )
|
15
30
|
]
|
16
31
|
|
17
32
|
def self.attach_to_current_container!
|
18
33
|
return if @after_response_attached
|
19
34
|
if current_container
|
20
|
-
require(current_container.lib)
|
35
|
+
require(current_container.lib) if current_container.lib
|
21
36
|
@after_response_attached = true
|
22
|
-
|
37
|
+
logger.info{ "[AfterResponse] => Callback hook installed for #{current_container.name}" }
|
23
38
|
else
|
24
|
-
|
39
|
+
logger.info{ "[AfterResponse] => No supported container found. AfterResponse will not buffer." }
|
25
40
|
end
|
26
41
|
end
|
27
42
|
|
43
|
+
def self.reset!
|
44
|
+
@after_response_attached = @current_container = @logger = nil
|
45
|
+
end
|
46
|
+
|
28
47
|
def self.current_container
|
29
48
|
@current_container ||= CONTAINER_ADAPTERS.detect{|c| c.test.call }
|
30
49
|
end
|
31
50
|
|
51
|
+
# AfterResponse is in a bufferable state mode only if it is running under a supported container
|
52
|
+
# where an after_response callback hook was installed and if an after_response callback
|
53
|
+
# was installed that calls Starboard::EventQueue.flush!
|
32
54
|
def self.bufferable?
|
33
|
-
|
55
|
+
current_container
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.logger
|
59
|
+
@logger ||= begin
|
60
|
+
if defined?(Rails)
|
61
|
+
Rails.logger
|
62
|
+
else
|
63
|
+
require 'logger'
|
64
|
+
Logger.new($stdout)
|
65
|
+
end
|
66
|
+
end
|
34
67
|
end
|
35
68
|
|
36
69
|
end
|
data/rails/init.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_response
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 9
|
9
|
+
version: "0.9"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kevin E. Hunt
|
@@ -14,15 +14,15 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-15 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: |
|
22
|
-
AfterResponse provides callbacks into the Passenger2
|
22
|
+
AfterResponse provides callbacks into the Passenger2.2, Passenger3 and Unicorn
|
23
23
|
request cycle. The main goal is to delay as much non-critical processing until later, delivering
|
24
|
-
the response to the client application sooner. This would mainly include logging data into a
|
25
|
-
service, sending email and other tasks that do not affect the response body in any way.
|
24
|
+
the response to the client application sooner. This would mainly include logging data into a Observatory-like
|
25
|
+
event logging service, sending email and other tasks that do not affect the response body in any way.
|
26
26
|
|
27
27
|
email: kevin@kev.in
|
28
28
|
executables: []
|