http-double 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http_double/request_logger.rb +35 -13
- data/lib/http_double/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2481a69325fb8b81a08f9dcc1009239536cadaf
|
4
|
+
data.tar.gz: e178067a35712c22b02e09e3bf84f71c54f88ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b1aa2fded59adff9de2ff499191e16d2cee124e18870daf97557b820912ec7b6b13d71182278d3b0fbdb3dc0a77122ca11f1458a819efb6be19e3e4aa9b693
|
7
|
+
data.tar.gz: 3e0116b8a8470414734a885c7fc549358087e06d2d4b60466eec54cc3923b2a1cb00ad9cd21c2b6a747d58592c942b336e09f9fa25ee151a4eb0fbd52d6df5f0
|
@@ -1,11 +1,8 @@
|
|
1
1
|
require 'rack/utils'
|
2
|
-
require 'ostruct'
|
3
2
|
require 'active_support/hash_with_indifferent_access'
|
4
3
|
|
5
4
|
class HttpDouble::RequestLogger
|
6
|
-
|
7
|
-
# noinspection RubyConstantNamingConvention
|
8
|
-
IHash = ActiveSupport::HashWithIndifferentAccess
|
5
|
+
include ActiveSupport
|
9
6
|
|
10
7
|
def initialize(app, log)
|
11
8
|
@app = app
|
@@ -13,14 +10,35 @@ class HttpDouble::RequestLogger
|
|
13
10
|
end
|
14
11
|
|
15
12
|
def call(env)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
@app.call(env).tap do |response|
|
14
|
+
@log << RoundTrip.new(
|
15
|
+
Request.new(env),
|
16
|
+
Response.new(
|
17
|
+
response[0],
|
18
|
+
HashWithIndifferentAccess.new(response[1]),
|
19
|
+
response[2].join
|
20
|
+
)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class RoundTrip
|
26
|
+
attr_reader :request, :response
|
27
|
+
|
28
|
+
def initialize(request, response)
|
29
|
+
@request = request
|
30
|
+
@response = response
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Response
|
35
|
+
attr_reader :code, :headers, :body
|
36
|
+
|
37
|
+
def initialize(code, headers, body)
|
38
|
+
@code = code
|
39
|
+
@headers = headers
|
40
|
+
@body = body
|
41
|
+
end
|
24
42
|
end
|
25
43
|
|
26
44
|
class Request
|
@@ -72,7 +90,11 @@ class HttpDouble::RequestLogger
|
|
72
90
|
end
|
73
91
|
|
74
92
|
def form_fields
|
75
|
-
@form_fields ||=
|
93
|
+
@form_fields ||= HashWithIndifferentAccess.new(
|
94
|
+
Rack::Utils.parse_query(body).map do |key, value|
|
95
|
+
[key.to_sym, value.is_a?(Array) ? value : [value]]
|
96
|
+
end.to_h
|
97
|
+
)
|
76
98
|
end
|
77
99
|
|
78
100
|
def json_input
|
data/lib/http_double/version.rb
CHANGED