forked from hubertlepicki/rack-reverse-proxy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HttpStreamingResponse patch to support webmock and solve #1
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## | ||
# Patch HttpStreamingResponse | ||
# in order to support webmocks and still use rack-proxy | ||
# | ||
# Inspired by @ehlertij commits on sportngin/rack-proxy: | ||
# 616574e452fa731f5427d2ff2aff6823fcf28bde | ||
# d8c377f7485997b229ced23c33cfef87d3fb8693 | ||
# 75b446a26ceb519ddc28f38b33309e9a2799074c | ||
# | ||
module Rack | ||
class HttpStreamingResponse | ||
def each(&block) | ||
response.read_body(&block) | ||
ensure | ||
session.end_request_hacked unless mocking? | ||
end | ||
|
||
protected | ||
|
||
def response | ||
if mocking? | ||
@response ||= session.request(@request) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def mocking? | ||
defined?(WebMock) || defined?(FakeWeb) | ||
end | ||
end | ||
end |