Skip to content

Commit

Permalink
use basic authentication if user information is present in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dbackeus committed Aug 9, 2011
1 parent 197b5bb commit c8f4197
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/httpi/request.rb
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions spec/httpi/request_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit c8f4197

Please sign in to comment.