-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from mamantoha/proxy-redirect
use proxy on redirects
- Loading branch information
Showing
6 changed files
with
69 additions
and
2 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,33 @@ | ||
require "../spec_helper" | ||
|
||
describe Crest do | ||
describe "With proxy server" do | ||
it "should make request" do | ||
with_proxy_server do |host, port, wants_close| | ||
response = Crest.get("#{TEST_SERVER_URL}/", p_addr: host, p_port: port) | ||
(response.status_code).should eq(200) | ||
(response.body).should contain("Hello World!") | ||
(response.request.p_addr).should eq("127.0.0.1") | ||
(response.request.p_port).should eq(8080) | ||
ensure | ||
wants_close.send(nil) | ||
end | ||
end | ||
|
||
it "should redirect with proxy" do | ||
with_proxy_server do |host, port, wants_close| | ||
response = Crest.get("#{TEST_SERVER_URL}/redirect", p_addr: "127.0.0.1", p_port: 8080) | ||
(response.status_code).should eq(200) | ||
(response.body).should contain("Hello World!") | ||
(response.url).should eq("#{TEST_SERVER_URL}/") | ||
(response.history.size).should eq(1) | ||
(response.history.first.url).should eq("#{TEST_SERVER_URL}/redirect") | ||
(response.history.first.status_code).should eq(302) | ||
(response.request.p_addr).should eq("127.0.0.1") | ||
(response.request.p_port).should eq(8080) | ||
ensure | ||
wants_close.send(nil) | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,5 +1,24 @@ | ||
require "spec" | ||
require "json" | ||
require "http_proxy" | ||
require "../src/crest" | ||
|
||
TEST_SERVER_URL = "http://127.0.0.1:4567" | ||
|
||
def with_proxy_server(host = "127.0.0.1", port = 8080) | ||
wants_close = Channel(Nil).new | ||
server = HTTP::Proxy::Server.new(host, port) | ||
|
||
spawn do | ||
server.listen | ||
end | ||
|
||
spawn do | ||
wants_close.receive | ||
server.close | ||
end | ||
|
||
Fiber.yield | ||
|
||
yield host, port, wants_close | ||
end |
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