request-replay 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +9 -22
- data/Rakefile +1 -1
- data/lib/request-replay/middleware.rb +9 -3
- data/request-replay.gemspec +2 -2
- data/test/test_basic.rb +43 -10
- 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: 82468210714a1dd60ceadcd91e95752c0e85ce85
|
4
|
+
data.tar.gz: 906d7755d38d5a0748707068bc1f31d7c34beadb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf7b7b776083558e322f502a0de20cccf7dc51e4cd14f0be2a8eddfd8316fe3748add3a749ac336f50567e6c33755da185b8a2bd52618d2ef706a521f9f691e3
|
7
|
+
data.tar.gz: f61d88e1673fb50cc512e87b8702dc2ddeb51bf6e7976a90ecf3982033c1f243d477299eb5fe1b4db6dc199da29f773091af90dcaf39262d367cf1eabd5cc17b
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -31,28 +31,15 @@ overwrite in the original request.
|
|
31
31
|
``` ruby
|
32
32
|
require 'request-replay'
|
33
33
|
use RequestReplay::Middleware, 'localhost:8080',
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
use Class.new{
|
44
|
-
def initialize app, host, options={}
|
45
|
-
@app, @host, @options = app, host, options
|
46
|
-
end
|
47
|
-
|
48
|
-
def call env
|
49
|
-
# We don't want to read the socket in a thread, so create it in main
|
50
|
-
# thread, and send the data in a thread as we don't care the responses
|
51
|
-
Thread.new(RequestReplay.new(env, @host, @options), &:start)
|
52
|
-
@app.call(env)
|
53
|
-
end
|
54
|
-
}, 'localhost:8080', :add_headers => {'Host' => 'example.com'},
|
55
|
-
:read_wait => 5
|
34
|
+
:add_headers => {'Host' => 'example.com'},
|
35
|
+
:read_wait => 5,
|
36
|
+
# We could also rewrite the env
|
37
|
+
:rewrite_env => lambda{ |env|
|
38
|
+
if env['HTTP_HOST'].start_with?('api.')
|
39
|
+
env['PATH_INFO'] = "/api/#{env['PATH_INFO']}"
|
40
|
+
end
|
41
|
+
env
|
42
|
+
}
|
56
43
|
run lambda{ |env| [200, {}, [env.inspect]] }
|
57
44
|
```
|
58
45
|
|
data/Rakefile
CHANGED
@@ -7,11 +7,17 @@ class RequestReplay::Middleware
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call env
|
10
|
+
# Unfortunately, we need to dup env because other middleware might be
|
11
|
+
# modifying it and make RequestReplay not able to get the original env.
|
12
|
+
rr_env = if rewrite = @options[:rewrite_env]
|
13
|
+
rewrite.call(env.dup)
|
14
|
+
else
|
15
|
+
env.dup
|
16
|
+
end
|
17
|
+
|
10
18
|
# We don't want to read the socket in a thread, so create it in main
|
11
19
|
# thread, and send the data in a thread as we don't care the responses.
|
12
|
-
|
13
|
-
# might be modifying it and make it not able to get the original env.
|
14
|
-
Thread.new(RequestReplay.new(env.dup, @host, @options), &:start)
|
20
|
+
Thread.new(RequestReplay.new(rr_env, @host, @options), &:start)
|
15
21
|
@app.call(env)
|
16
22
|
end
|
17
23
|
end
|
data/request-replay.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: request-replay 0.6.
|
2
|
+
# stub: request-replay 0.6.2 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "request-replay"
|
6
|
-
s.version = "0.6.
|
6
|
+
s.version = "0.6.2"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
data/test/test_basic.rb
CHANGED
@@ -15,14 +15,14 @@ require 'request-replay'
|
|
15
15
|
require 'rack'
|
16
16
|
|
17
17
|
describe RequestReplay do
|
18
|
-
host = 'localhost'
|
18
|
+
host = 'localhost'.freeze
|
19
19
|
port = 1024 + rand(2**16 - 1024)
|
20
20
|
serv = TCPServer.new('localhost', port)
|
21
|
-
hopt = "#{host}:#{port}"
|
21
|
+
hopt = "#{host}:#{port}".freeze
|
22
22
|
env = {'REQUEST_METHOD' => 'GET',
|
23
23
|
'PATH_INFO' => '/', 'QUERY_STRING' => 'q=1',
|
24
24
|
'HTTP_HOST' => 'localhost',
|
25
|
-
'HTTP_PORK' => 'BEEF' }
|
25
|
+
'HTTP_PORK' => 'BEEF' }.freeze
|
26
26
|
|
27
27
|
verify = lambda do |response, expected|
|
28
28
|
sock = serv.accept
|
@@ -103,17 +103,22 @@ Pork: BEEF\r
|
|
103
103
|
end
|
104
104
|
|
105
105
|
app.call(env.merge('REQUEST_METHOD' => 'PUT'))
|
106
|
-
|
107
|
-
|
106
|
+
begin
|
107
|
+
sock = serv.accept
|
108
|
+
sock.read.should.eq <<-HTTP
|
108
109
|
PUT /?q=1 HTTP/1.1\r
|
109
110
|
Host: localhost\r
|
110
111
|
Pork: BEEF\r
|
111
112
|
\r
|
112
113
|
HTTP
|
113
|
-
|
114
|
+
ensure
|
115
|
+
sock.close
|
116
|
+
end
|
114
117
|
end
|
115
118
|
|
116
119
|
should 'retain original env' do
|
120
|
+
e = env.dup
|
121
|
+
|
117
122
|
app = Rack::Builder.app do
|
118
123
|
use RequestReplay::Middleware, hopt
|
119
124
|
run lambda{ |env|
|
@@ -122,15 +127,43 @@ Pork: BEEF\r
|
|
122
127
|
}
|
123
128
|
end
|
124
129
|
|
125
|
-
app.call(
|
126
|
-
|
127
|
-
|
130
|
+
app.call(e)
|
131
|
+
begin
|
132
|
+
sock = serv.accept
|
133
|
+
sock.read.should.eq <<-HTTP
|
128
134
|
GET /?q=1 HTTP/1.1\r
|
129
135
|
Host: localhost\r
|
130
136
|
Pork: BEEF\r
|
131
137
|
\r
|
132
138
|
HTTP
|
133
|
-
|
139
|
+
ensure
|
140
|
+
sock.close
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
should 'rewrite_env' do
|
145
|
+
app = Rack::Builder.app do
|
146
|
+
use RequestReplay::Middleware, hopt, :rewrite_env => lambda{ |env|
|
147
|
+
if env['HTTP_HOST'].start_with?('api.')
|
148
|
+
env['PATH_INFO'] = "/api#{env['PATH_INFO']}"
|
149
|
+
end
|
150
|
+
env
|
151
|
+
}, :add_headers => {'Host' => 'eg.com'}
|
152
|
+
run lambda{ |env| [200, {}, []] }
|
153
|
+
end
|
154
|
+
|
155
|
+
app.call(env.merge('HTTP_HOST' => 'api.localhost'))
|
156
|
+
begin
|
157
|
+
sock = serv.accept
|
158
|
+
sock.read.should.eq <<-HTTP
|
159
|
+
GET /api/?q=1 HTTP/1.1\r
|
160
|
+
Host: eg.com\r
|
161
|
+
Pork: BEEF\r
|
162
|
+
\r
|
163
|
+
HTTP
|
164
|
+
ensure
|
165
|
+
sock.close
|
166
|
+
end
|
134
167
|
end
|
135
168
|
end
|
136
169
|
end
|