From 802996788d2317143f79451c52e5741176d25a71 Mon Sep 17 00:00:00 2001 From: Tom Brammar Date: Tue, 7 Jan 2020 11:52:59 +0100 Subject: [PATCH 1/4] return effective_url as string without port details --- lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb | 2 +- spec/acceptance/typhoeus/typhoeus_hydra_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb index 9c9b5ca72..53427e522 100644 --- a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +++ b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb @@ -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: request_signature.uri.omit(:port).to_s ) end response.mock = :webmock diff --git a/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb b/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb index 7e33bcc4f..3ac7853f1 100644 --- a/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +++ b/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb @@ -32,6 +32,14 @@ end end + describe 'effective_url' do + it "returns effective_url as string without 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 + 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'}) From 01f5ea99d178cb5f4ebe9c01f474c552478f8b65 Mon Sep 17 00:00:00 2001 From: Tom Brammar Date: Tue, 7 Jan 2020 18:26:33 +0100 Subject: [PATCH 2/4] only remove custom ports --- .../typhoeus_hydra_adapter.rb | 9 ++++++- .../typhoeus/typhoeus_hydra_spec.rb | 26 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb index 53427e522..930b71e0e 100644 --- a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +++ b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb @@ -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.omit(:port).to_s + effective_url: effective_url(request_signature.uri) ) end response.mock = :webmock @@ -168,6 +168,13 @@ def self.request_hash(request_signature) end res end + + private + + def self.effective_url(uri) + return uri.omit(:port).to_s if [80, 443].include?(uri.port) + uri.to_s + end end end end diff --git a/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb b/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb index 3ac7853f1..21a2d68ca 100644 --- a/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +++ b/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb @@ -33,10 +33,28 @@ end describe 'effective_url' do - it "returns effective_url as string without 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/' + 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 From a490f6a8cff3d5d96cad38f6ab4bde9e36ffa5c5 Mon Sep 17 00:00:00 2001 From: Tom Brammar Date: Wed, 8 Jan 2020 09:13:08 +0100 Subject: [PATCH 3/4] more descriptive method name --- lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb index 930b71e0e..b2ef1d931 100644 --- a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +++ b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb @@ -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: effective_url(request_signature.uri) + effective_url: standardise_stringify_uri(request_signature.uri) ) end response.mock = :webmock @@ -171,7 +171,7 @@ def self.request_hash(request_signature) private - def self.effective_url(uri) + def self.standardise_stringify_uri(uri) return uri.omit(:port).to_s if [80, 443].include?(uri.port) uri.to_s end From 101c3e802ab9695ea64045bc090d4fb2ab632a51 Mon Sep 17 00:00:00 2001 From: Tom Brammar Date: Wed, 8 Jan 2020 09:21:49 +0100 Subject: [PATCH 4/4] Use non-proper English --- lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb index b2ef1d931..36bf35e75 100644 --- a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +++ b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb @@ -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: standardise_stringify_uri(request_signature.uri) + effective_url: standardize_stringify_uri(request_signature.uri) ) end response.mock = :webmock @@ -171,7 +171,7 @@ def self.request_hash(request_signature) private - def self.standardise_stringify_uri(uri) + def self.standardize_stringify_uri(uri) return uri.omit(:port).to_s if [80, 443].include?(uri.port) uri.to_s end