Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return effective_url as string (without port details) #869

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
Expand Up @@ -102,7 +102,7 @@ def self.generate_typhoeus_response(request_signature, webmock_response)
status_message: webmock_response.status[1],
body: webmock_response.body,
headers: webmock_response.headers,
effective_url: request_signature.uri
effective_url: standardize_stringify_uri(request_signature.uri)
)
end
response.mock = :webmock
Expand Down Expand Up @@ -168,6 +168,13 @@ def self.request_hash(request_signature)
end
res
end

private

def self.standardize_stringify_uri(uri)
return uri.omit(:port).to_s if [80, 443].include?(uri.port)
uri.to_s
end
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/acceptance/typhoeus/typhoeus_hydra_spec.rb
Expand Up @@ -32,6 +32,32 @@
end
end

describe 'effective_url' do
context 'original request url is provided with custom port' do
it "returns effective_url as string with custom port" do
stub_request(:get, "http://www.example.com:8080").to_return(headers: {'X-Test' => '1'})
response = Typhoeus.get("http://www.example.com:8080")
expect(response.effective_url).to eq 'http://www.example.com:8080/'
end
end

context 'original request url is provided with standard port' do
it "returns effective_url as string with no port" do
stub_request(:get, "http://www.example.com:80").to_return(headers: {'X-Test' => '1'})
response = Typhoeus.get("http://www.example.com:80")
expect(response.effective_url).to eq 'http://www.example.com/'
end
end

context 'original request url is provided with no port' do
it "returns effective_url as string with no port" do
stub_request(:get, "http://www.example.com").to_return(headers: {'X-Test' => '1'})
response = Typhoeus.get("http://www.example.com")
expect(response.effective_url).to eq 'http://www.example.com/'
end
end
end

describe "when params are used" do
it "should take into account params for POST request" do
stub_request(:post, "www.example.com/?hello=world").with(query: {hello: 'world'})
Expand Down