Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 1687caf

Browse files
committed
Move #normalize_relative_uri into HttpClient
1 parent 0ddae8c commit 1687caf

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

lib/wpxf/net/http_client.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ def execute_delete_request(opts)
182182
def max_http_concurrency
183183
normalized_option_value('max_http_concurrency')
184184
end
185+
186+
# Normalize a relative URI into an absolute URL.
187+
# @param uri [String] the relative or absolute URI.
188+
# @return [String] the absolute URL.
189+
def normalize_relative_uri(uri)
190+
if uri.start_with?('/')
191+
normalize_uri(full_uri, uri)
192+
else
193+
uri
194+
end
195+
end
185196
end
186197
end
187198
end

lib/wpxf/net/typhoeus_helper.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ def create_typhoeus_request(opts)
3939
)
4040
Typhoeus::Request.new(normalize_relative_uri(opts[:url]), options)
4141
end
42-
43-
def normalize_relative_uri(uri)
44-
if uri.start_with?('/')
45-
normalize_uri(full_uri, uri)
46-
else
47-
uri
48-
end
49-
end
5042
end
5143
end
5244
end

spec/net/http_client_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,16 @@
350350
expect(queue.length).to eq 2
351351
end
352352
end
353+
354+
describe '#normalize_relative_uri' do
355+
it 'joins the uri on to the value of #full_uri if it starts with a forward slash' do
356+
allow(subject).to receive(:full_uri).and_return('http://127.0.0.1/path')
357+
expect(subject.normalize_relative_uri('/test.txt')).to eq 'http://127.0.0.1/path/test.txt'
358+
end
359+
360+
it 'uses the full url specified if it does not start with a forward slash' do
361+
allow(subject).to receive(:full_uri).and_return('http://127.0.0.1/path')
362+
expect(subject.normalize_relative_uri('www.github.com')).to eq 'www.github.com'
363+
end
364+
end
353365
end

spec/net/typhoeus_helper_spec.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,4 @@
8686
expect(req.url).to eq 'http://www.github.com/'
8787
end
8888
end
89-
90-
describe '#normalize_relative_uri' do
91-
it 'joins the uri on to the value of #full_uri if it starts with a forward slash' do
92-
expect(subject.normalize_relative_uri('/test.txt')).to eq 'http://127.0.0.1/path/test.txt'
93-
end
94-
95-
it 'uses the full url specified if it does not start with a forward slash' do
96-
expect(subject.normalize_relative_uri('www.github.com')).to eq 'www.github.com'
97-
end
98-
end
9989
end

0 commit comments

Comments
 (0)