diff --git a/lib/httpi/request.rb b/lib/httpi/request.rb index 456a4c2..f9971a2 100644 --- a/lib/httpi/request.rb +++ b/lib/httpi/request.rb @@ -24,6 +24,7 @@ def initialize(args = {}) # Sets the +url+ to access. Raises an +ArgumentError+ unless the +url+ is valid. def url=(url) @url = normalize_url! url + auth.basic @url.user, @url.password || '' if @url.user end # Returns the +url+ to access. diff --git a/spec/httpi/request_spec.rb b/spec/httpi/request_spec.rb index f4b8026..cec1367 100644 --- a/spec/httpi/request_spec.rb +++ b/spec/httpi/request_spec.rb @@ -31,6 +31,16 @@ it "raises an ArgumentError in case of an invalid url" do expect { request.url = "invalid" }.to raise_error(ArgumentError) end + + it "uses username and password as basic authentication if present in the URL" do + request.url = "http://username:password@example.com" + request.auth.basic.should == ['username', 'password'] + end + + it "uses a blank password if only username is specified in the URL" do + request.url = "http://username@example.com" + request.auth.basic.should == ['username', ''] + end end describe "#proxy" do