diff -urN http-access-2_0_6/lib/http-access2/http.rb http-access-2_0_6-su/lib/http-access2/http.rb
--- http-access-2_0_6/lib/http-access2/http.rb	2005-09-01 07:50:49.000000000 +0200
+++ http-access-2_0_6-su/lib/http-access2/http.rb	2005-10-13 23:44:31.000000000 +0200
@@ -190,6 +190,12 @@
       @header_item.push([key, value])
     end
 
+    def delete(key)
+      @header_item = @header_item.delete_if {|item|
+        item[0] == key
+      }
+    end
+
     def get(key = nil)
       if !key
 	@header_item
diff -urN http-access-2_0_6/lib/http-access2/negotiate.rb http-access-2_0_6-su/lib/http-access2/negotiate.rb
--- http-access-2_0_6/lib/http-access2/negotiate.rb	1970-01-01 01:00:00.000000000 +0100
+++ http-access-2_0_6-su/lib/http-access2/negotiate.rb	2005-10-13 23:59:19.000000000 +0200
@@ -0,0 +1,46 @@
+
+require 'gss'
+require 'base64'
+
+module HTTP
+module Auth
+
+class Negotiate
+  attr_accessor :mechanism
+  attr_accessor :uri
+  attr_accessor :ctx
+
+  def initialize(req,mech = Gss::Oid::KRB5_MECHANISM)
+     @uri = req.header.request_uri
+     @mechanism = mech   
+     @ctx = Gss::Context.new()
+     @target = Gss::Name.import(Gss::Oid::NT_HOSTBASED_SERVICE,"HTTP@#{@uri.host}")
+  end
+
+  def authenticate(req,res)
+   hdr = res.header.get('WWW-Authenticate')
+   done = true
+   if !hdr.nil? && hdr.length > 0 && hdr[0][1] =~ /^Negotiate\s*(.*)\s*/
+      token = $1.nil? || $1.length == 0 ? nil : Base64.decode64($1)
+      istep = Gss::Step.new(token,@mechanism,Gss::MUTUAL_FLAG,0)
+      ostep = Gss::Step.new()
+      status = @ctx.init(Gss::Credential::NO_CREDENTIAL,@target,istep,Gss::ChannelBindings::NO_CHANNEL_BINDINGS,ostep)
+      if status.major == Gss::S_CONTINUE_NEEDED || (status.major == Gss::S_COMPLETE && !ostep.token.nil?)
+         data = Base64.encode64(ostep.token)
+         data = data.gsub(/\n/,'');
+         req.header.delete("Authorization");
+         req.header.set("Authorization","Negotiate #{data}")
+         done = false
+      else
+         if status.major != Gss::S_COMPLETE
+            res.header.set("Client-Warning","#{$status}");
+            done = true
+         end
+      end
+   end
+   done
+  end
+
+end
+end
+end
diff -urN http-access-2_0_6/lib/http-access2.rb http-access-2_0_6-su/lib/http-access2.rb
--- http-access-2_0_6/lib/http-access2.rb	2005-09-13 05:20:38.000000000 +0200
+++ http-access-2_0_6-su/lib/http-access2.rb	2005-10-13 23:57:17.000000000 +0200
@@ -19,6 +19,7 @@
 # Extra library
 require 'http-access2/http'
 require 'http-access2/cookie'
+require 'http-access2/negotiate'
 
 
 module HTTPAccess2
@@ -360,18 +361,53 @@
     raise RuntimeError.new("Retry count exceeded.")
   end
 
+  def send_receive(conn,method, uri, query, body, extheader, proxy, &block)
+     req = create_request(method, uri, query, body, extheader, !proxy.nil?)
+     send_receive_i(req,proxy,conn,&block)
+     req
+  end
+
+  def send_receive_i(req, proxy, conn, &block)
+     begin
+        do_get_block(req, proxy, conn, &block)
+     rescue Session::KeepAliveDisconnected
+        do_get_block(req, proxy, conn, &block)
+     end
+  end
+
   def conn_request(conn, method, uri, query, body, extheader, &block)
     unless uri.is_a?(URI)
       uri = URI.parse(uri)
     end
     proxy = no_proxy?(uri) ? nil : @proxy
-    begin
-      req = create_request(method, uri, query, body, extheader, !proxy.nil?)
-      do_get_block(req, proxy, conn, &block)
-    rescue Session::KeepAliveDisconnected
-      req = create_request(method, uri, query, body, extheader, !proxy.nil?)
-      do_get_block(req, proxy, conn, &block)
+    content = []
+    i = 0
+    content[i] = []
+    req = send_receive(conn, method, uri, query, body, extheader, proxy) {|str| content[i].push(str)}
+    res = conn.pop
+#puts "1===============> "
+#p res
+    authHeader = res.header.get("WWW-Authenticate")
+    if res.header.response_status_code == 401 && authHeader != nil && authHeader.length > 0
+       if authHeader[0][1] =~ /Negotiate/
+          auth = HTTP::Auth::Negotiate.new(req)
+          while res.header.response_status_code == 401 && !auth.authenticate(req,res)
+            i = i+1
+            content[i] = []
+            send_receive_i(req,proxy,conn){|str| content[i].push(str)}
+            res = conn.pop
+#puts "2===============> "
+#p res
+          end
+       end
+    else
+      i = 1 
     end
+
+    content[i-1].find{|str| 
+        block.call(str) if block
+    }
+    conn.push(res)
   end
 
   def create_request(method, uri, query, body, extheader, proxy)
diff -urN http-access-2_0_6/sample/swcat.rb http-access-2_0_6-su/sample/swcat.rb
--- http-access-2_0_6/sample/swcat.rb	1970-01-01 01:00:00.000000000 +0100
+++ http-access-2_0_6-su/sample/swcat.rb	2005-10-10 20:14:58.000000000 +0200
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+# wcat for http-access2
+# Copyright (C) 2001 TAKAHASHI Masayoshi
+
+$:.unshift(File.join('..', 'lib'))
+require 'http-access2'
+
+if ENV['HTTP_PROXY']
+  h = HTTPAccess2::Client.new(ENV['HTTP_PROXY'])
+else
+  h = HTTPAccess2::Client.new()
+end
+
+h.ssl_config.set_trust_ca(ENV['TRUSTCA'])
+  
+while urlstr = ARGV.shift
+  response = h.get(urlstr){ |data|
+    print data
+  }
+  p response.contenttype
+end

