diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-03-13 05:55:31 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-03-13 05:55:31 +0000 |
commit | 6c5be1e7d626a242a1cde83b7d02d65380d35d8e (patch) | |
tree | 8db32f54a31fc68d3d80b1333c9c5b6c97a8c91b /lib/net | |
parent | 54e1bd79015ff7584ba034bd17c1b3be955891af (diff) |
aamine
* lib/net/http.rb: add HTTPRequest#basic_auth.
* lib/net/smtp.rb: raise if only account or password is given.
* lib/net/protocol.rb: WriteAdapter#<< returns self.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r-- | lib/net/http.rb | 9 | ||||
-rw-r--r-- | lib/net/protocol.rb | 5 | ||||
-rw-r--r-- | lib/net/smtp.rb | 13 |
3 files changed, 17 insertions, 10 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb index 628adb7d14..26e5285525 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -719,9 +719,9 @@ module Net d1 = m[1].to_i d2 = m[2].to_i - if m[1] and m[2] then arr.push d1 .. d2 - elsif m[1] then arr.push d1 .. -1 - elsif m[2] then arr.push -d2 .. -1 + if m[1] and m[2] then arr.push (d1 .. d2) + elsif m[1] then arr.push (d1 .. -1) + elsif m[2] then arr.push (-d2 .. -1) else raise HTTPHeaderSyntaxError, 'range is not specified' end @@ -793,7 +793,8 @@ module Net end def basic_auth( acc, pass ) - @header['authorization'] = ["#{acc}:#{pass}"].pack('m').gsub(/\s+/, '') + @header['authorization'] = + 'Basic ' + ["#{acc}:#{pass}"].pack('m').gsub(/\s+/, '') end end diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index c9ff791dbd..343721add3 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -361,7 +361,10 @@ module Net @sock.__send__ @mid, str end - alias << write + def <<( str ) + @sock.__send__ @mid, str + self + end end diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index 3645da0f78..befc1adf03 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -151,12 +151,15 @@ module Net end end - if user and secret then + if user or secret then + (user and secret) or + raise ArgumentError, 'both of account and password are required' + mid = 'auth_' + (authtype || 'cram_md5').to_s - unless @command.respond_to? mid then - raise ArgumentError, "wrong auth type #{authtype.to_s}" - end - @command.send mid, user, secret + @command.respond_to? mid or + raise ArgumentError, "wrong auth type #{authtype.to_s}" + + @command.__send__ mid, user, secret end end |