request_recorder 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock
CHANGED
@@ -6,6 +6,7 @@ module RequestRecorder
|
|
6
6
|
class Middleware
|
7
7
|
MARKER = "__request_recording"
|
8
8
|
MAX_STEPS = 100
|
9
|
+
SEPARATOR = "|"
|
9
10
|
|
10
11
|
def initialize(app, options={})
|
11
12
|
@app = app
|
@@ -39,7 +40,7 @@ module RequestRecorder
|
|
39
40
|
def read_state_from_env(env)
|
40
41
|
request = Rack::Request.new(env)
|
41
42
|
if request.cookies[MARKER]
|
42
|
-
steps, id = request.cookies[MARKER].split(
|
43
|
+
steps, id = request.cookies[MARKER].split(SEPARATOR)
|
43
44
|
[steps.to_i, id]
|
44
45
|
else
|
45
46
|
[env["QUERY_STRING"][/#{MARKER}=(\d+)/, 1].to_i, nil]
|
@@ -52,7 +53,7 @@ module RequestRecorder
|
|
52
53
|
if to_go <= 1
|
53
54
|
response.delete_cookie(MARKER)
|
54
55
|
else
|
55
|
-
response.set_cookie(MARKER, {:value => "#{to_go.to_i - 1}
|
56
|
+
response.set_cookie(MARKER, {:value => "#{to_go.to_i - 1}#{SEPARATOR}#{id}", :expires => Time.now+24*60*60, :httponly => true})
|
56
57
|
end
|
57
58
|
|
58
59
|
response.finish # finish writes out the response in the expected format.
|
@@ -8,7 +8,7 @@ module RequestRecorder
|
|
8
8
|
|
9
9
|
def write(id, text)
|
10
10
|
old = (id ? @redis.hget(KEY, id) : "")
|
11
|
-
id = "#{Time.now.
|
11
|
+
id = "#{Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")}_#{Process.pid}" unless id
|
12
12
|
@redis.hset(KEY, id, old.to_s + text)
|
13
13
|
id
|
14
14
|
end
|
@@ -41,12 +41,12 @@ describe RequestRecorder do
|
|
41
41
|
it "sets cookie in first step" do
|
42
42
|
status, headers, body = middleware.call(activate_logger)
|
43
43
|
generated_id = stored.keys.last
|
44
|
-
headers["Set-Cookie"].should include "__request_recording=9%
|
44
|
+
headers["Set-Cookie"].should include "__request_recording=9%7C#{generated_id.gsub(":", "%3A").gsub(" ", "+")}; expires="
|
45
45
|
headers["Set-Cookie"].should include "; HttpOnly"
|
46
46
|
end
|
47
47
|
|
48
48
|
it "appends to existing log" do
|
49
|
-
middleware.call("HTTP_COOKIE" => "__request_recording=8
|
49
|
+
middleware.call("HTTP_COOKIE" => "__request_recording=8|#{existing_request_id}")
|
50
50
|
existing_request = redis.hget(redis_key, existing_request_id)
|
51
51
|
existing_request.should include "SELECT"
|
52
52
|
existing_request.should include "BEFORE"
|
@@ -55,19 +55,19 @@ describe RequestRecorder do
|
|
55
55
|
it "creates a new log if redis dies" do
|
56
56
|
existing_request_id # store key
|
57
57
|
redis.flushall
|
58
|
-
middleware.call("HTTP_COOKIE" => "__request_recording=8
|
58
|
+
middleware.call("HTTP_COOKIE" => "__request_recording=8|#{existing_request_id}")
|
59
59
|
existing_request = redis.hget(redis_key, existing_request_id)
|
60
60
|
existing_request.should include "SELECT"
|
61
61
|
existing_request.should_not include "BEFORE"
|
62
62
|
end
|
63
63
|
|
64
64
|
it "decrements cookie on each step" do
|
65
|
-
status, headers, body = middleware.call("HTTP_COOKIE" => "__request_recording=2
|
66
|
-
headers["Set-Cookie"].should include "__request_recording=1%
|
65
|
+
status, headers, body = middleware.call("HTTP_COOKIE" => "__request_recording=2|#{existing_request_id};foo=bar")
|
66
|
+
headers["Set-Cookie"].should include "__request_recording=1%7C#{existing_request_id}; expires="
|
67
67
|
end
|
68
68
|
|
69
69
|
it "removes cookie if final step is reached" do
|
70
|
-
status, headers, body = middleware.call("HTTP_COOKIE" => "__request_recording=1
|
70
|
+
status, headers, body = middleware.call("HTTP_COOKIE" => "__request_recording=1|#{existing_request_id};foo=bar")
|
71
71
|
headers["Set-Cookie"].should include "__request_recording=; expires="
|
72
72
|
end
|
73
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_recorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
segments:
|
62
62
|
- 0
|
63
|
-
hash:
|
63
|
+
hash: 4362379118001674709
|
64
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
segments:
|
71
71
|
- 0
|
72
|
-
hash:
|
72
|
+
hash: 4362379118001674709
|
73
73
|
requirements: []
|
74
74
|
rubyforge_project:
|
75
75
|
rubygems_version: 1.8.24
|