Skip to content

Commit 64e7034

Browse files
committed
Tidy up proxy spec.
1 parent 341dec9 commit 64e7034

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

spec/async/http/proxy_spec.rb

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,48 +136,50 @@
136136
host, port = request.path.split(":", 2)
137137
endpoint = Async::IO::Endpoint.tcp(host, port)
138138

139+
Async.logger.debug(self) {"Making connection to #{endpoint}..."}
140+
139141
Async::HTTP::Body::Hijack.response(request, 200, {}) do |stream|
140142
upstream = Async::IO::Stream.new(endpoint.connect)
143+
Async.logger.debug(self) {"Connected to #{upstream}..."}
141144

142145
reader = Async do
143146
while chunk = upstream.read_partial
144147
stream.write(chunk)
145148
stream.flush
146149
end
147150

151+
ensure
152+
Async.logger.debug(self) {"Finished reading from upstream..."}
148153
stream.close_write
149154
end
150155

151156
writer = Async do
152-
begin
153-
while chunk = stream.read_partial
154-
upstream.write(chunk)
155-
upstream.flush
156-
end
157-
158-
upstream.close_write
159-
rescue Async::Wrapper::Cancelled
160-
#ignore
157+
while chunk = stream.read_partial
158+
upstream.write(chunk)
159+
upstream.flush
161160
end
162-
end
163-
164-
begin
165-
reader.wait
166-
writer.wait
167-
161+
162+
rescue Async::Wrapper::Cancelled
163+
#ignore
168164
ensure
169-
upstream.close
170-
stream.close
165+
Async.logger.debug(self) {"Finished writing to upstream..."}
166+
upstream.close_write
171167
end
168+
169+
reader.wait
170+
writer.wait
171+
ensure
172+
upstream.close
173+
stream.close
172174
end
173175
end
174176
end
175177

176178
it 'can get insecure website' do
177-
endpoint = Async::HTTP::Endpoint.parse("http://www.codeotaku.com")
179+
endpoint = Async::HTTP::Endpoint.parse("http://www.google.com")
178180
proxy_client = client.proxied_client(endpoint)
179181

180-
response = proxy_client.get("/index")
182+
response = proxy_client.get("/search")
181183
expect(response).to_not be_failure
182184

183185
# The response would be a redirect:
@@ -191,10 +193,10 @@
191193
end
192194

193195
it 'can get secure website' do
194-
endpoint = Async::HTTP::Endpoint.parse("https://www.codeotaku.com")
196+
endpoint = Async::HTTP::Endpoint.parse("https://www.google.com")
195197
proxy_client = client.proxied_client(endpoint)
196198

197-
response = proxy_client.get("/index")
199+
response = proxy_client.get("/search")
198200

199201
expect(response).to_not be_failure
200202
expect(response.read).to_not be_empty

0 commit comments

Comments
 (0)