summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-16 13:17:10 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-16 13:17:10 +0000
commitae2c8b45d2c345faea6a7f2203603b4862f3a66c (patch)
tree226c7ff4ba8c308542832289824318291437f58e /lib
parent30aa46db0b3983648cb9a5d2cc330acad022f165 (diff)
* lib/net/http.rb: merge Ruby-SSPI patch contributed by Justin Bailey.
* ext/Win32API/lib/win32/sspi.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/http.rb65
1 files changed, 49 insertions, 16 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 46d95b27b4..00d9a535b9 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -1,8 +1,8 @@
#
# = net/http.rb
#
-# Copyright (c) 1999-2006 Yukihiro Matsumoto
-# Copyright (c) 1999-2006 Minero Aoki
+# Copyright (c) 1999-2007 Yukihiro Matsumoto
+# Copyright (c) 1999-2007 Minero Aoki
# Copyright (c) 2001 GOTOU Yuuzou
#
# Written and maintained by Minero Aoki <aamine@loveruby.net>.
@@ -1035,27 +1035,32 @@ module Net #:nodoc:
}
end
if proxy_user()
- unless use_ssl?
- req.proxy_basic_auth proxy_user(), proxy_pass()
- end
+ req.proxy_basic_auth proxy_user(), proxy_pass() unless use_ssl?
end
-
req.set_body_internal body
- begin_transport req
- req.exec @socket, @curr_http_version, edit_path(req.path)
- begin
- res = HTTPResponse.read_new(@socket)
- end while res.kind_of?(HTTPContinue)
- res.reading_body(@socket, req.response_body_permitted?) {
- yield res if block_given?
- }
- end_transport req, res
-
+ res = transport_request(req, &block)
+ if sspi_auth?(res)
+ sspi_auth(req)
+ res = transport_request(req, &block)
+ end
res
end
private
+ def transport_request(req)
+ begin_transport req
+ req.exec @socket, @curr_http_version, edit_path(req.path)
+ begin
+ res = HTTPResponse.read_new(@socket)
+ end while res.kind_of?(HTTPContinue)
+ res.reading_body(@socket, req.response_body_permitted?) {
+ yield res if block_given?
+ }
+ end_transport req, res
+ res
+ end
+
def begin_transport(req)
if @socket.closed?
connect
@@ -1096,6 +1101,34 @@ module Net #:nodoc:
(@curr_http_version == '1.1')
end
+ def sspi_auth?(res)
+ return false unless @sspi_enabled
+ if res.kind_of?(HTTPProxyAuthenticationRequired) and
+ proxy? and res["Proxy-Authenticate"].include?("Negotiate")
+ begin
+ require 'win32/sspi'
+ true
+ rescue LoadError
+ false
+ end
+ else
+ false
+ end
+ end
+
+ def sspi_auth(req)
+ n = Win32::SSPI::NegotiateAuth.new
+ req["Proxy-Authorization"] = "Negotiate #{n.get_initial_token}"
+ # Some versions of ISA will close the connection if this isn't present.
+ req["Connection"] = "Keep-Alive"
+ req["Proxy-Connection"] = "Keep-Alive"
+ res = transport_request(req)
+ authphrase = res["Proxy-Authenticate"] or return res
+ req["Proxy-Authorization"] = "Negotiate #{n.complete_authentication(authphrase)}"
+ rescue => err
+ raise HTTPAuthenticationError.new('HTTP authentication failed', err)
+ end
+
#
# utils
#