Class: Net::HTTP
- Inherits:
-
Object
- Object
- Net::HTTP
- Defined in:
- lib/www/mechanize/monkey_patch.rb,
lib/www/ntlm-http/lib/net/ntlm_http.rb
Instance Method Summary collapse
- #keep_alive?(req, res) ⇒ Boolean
- #old_keep_alive? ⇒ Object
- #request(req, body = nil, &block) ⇒ Object
Instance Method Details
#keep_alive?(req, res) ⇒ Boolean
4 5 6 7 8 9 10 11 12 |
# File 'lib/www/mechanize/monkey_patch.rb', line 4 def keep_alive?(req, res) return false if /close/i =~ req['connection'].to_s return false if @seems_1_0_server return false if /close/i =~ res['connection'].to_s return true if /keep-alive/i =~ res['connection'].to_s return false if /close/i =~ res['proxy-connection'].to_s return true if /keep-alive/i =~ res['proxy-connection'].to_s (@curr_http_version == '1.1') end |
#old_keep_alive? ⇒ Object
3 |
# File 'lib/www/mechanize/monkey_patch.rb', line 3 alias :old_keep_alive? :keep_alive? |
#request(req, body = nil, &block) ⇒ Object
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
# File 'lib/www/ntlm-http/lib/net/ntlm_http.rb', line 819 def request req, body=nil, &block resp = data = auth_data = nil old_request req, body do |resp| unless Net::HTTPUnauthorized === resp and auth_data = req.auth_data and auth_data[0] == :ntlm and resp['www-authenticate'] == 'NTLM' || data = resp['www-authenticate'][/^NTLM (.*)/, 1] data = false yield resp if block_given? end end return resp if data == false # not really sure if i'm supposed to just rewrite the request like this? # and the body? what about redirects? the resp.content is just the text error message # what about post data? req.reuse unless data # first stage handshake. respond to challenge # puts "* authenticating (0) ..." # this time wait is true. req.ntlm_auth(*auth_data[1..2]) request req, body, &block else # puts "* authenticating (1) ..." challenge = Net::NTLM::Message.decode64 data # challenge.target_name could be provided back as a prompt. # maybe if password is unspecified, a callback can be used to provide # a user prompt. resp = challenge.response({:user => auth_data[1], :password => auth_data[2]}, {:ntlmv2 => true}) req['Authorization'] = 'NTLM ' + resp.encode64 old_request(req, body) { |resp| yield resp if block_given? } resp end end |