aboutsummaryrefslogtreecommitdiffstats
path: root/lib/net/http.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-03-05 10:25:53 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-03-05 10:25:53 +0000
commitb014cc337ef28498311f58a7b28bdfffebc53f00 (patch)
tree3cd5ad06eca04c69ae860e1421a06d0f73b281f4 /lib/net/http.rb
parent4890f3a684aff94d93a5cc3f68fa8c67c1da6c19 (diff)
downloadruby-b014cc337ef28498311f58a7b28bdfffebc53f00.tar.gz
Version 1.1.6
o all: use 'attr_reader/writer' instead of 'attr' o http.rb: get/head allow implicit 'start' o http.rb: change connection state algorithm o http.rb: process user header before write o protocol.rb: refine start/finish o protocol.rb: Command#last_reply o protocol.rb: ReplyCode.error! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r--lib/net/http.rb65
1 files changed, 40 insertions, 25 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 4ae5349202..104dca9681 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -3,7 +3,7 @@
= net/http.rb
maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
-This file is derived from http-access.rb
+This file is derived from "http-access.rb".
This library is distributed under the terms of the Ruby license.
You can freely distribute/modify this library.
@@ -22,7 +22,7 @@ class HTTPBadResponse < HTTPError; end
=begin
-= HTTP class
+= class HTTP
== Class Methods
@@ -62,39 +62,58 @@ class HTTPBadResponse < HTTPError; end
def get( path, u_header = nil, ret = '' )
- header = connecting {
+ u_header ||= {}
+ header = connecting( u_header ) {
@command.get ret, edit_path(path), u_header
}
+
return header, ret
end
def head( path, u_header = nil )
- connecting {
+ u_header ||= {}
+ header = connecting( u_header ) {
@command.head edit_path(path), u_header
}
+
+ header
end
private
- def connecting
- if @socket.closed? then
+ # called when connecting
+ def do_finish
+ unless @socket.closed? then
+ @command.head '/', { 'Connection' => 'Close' }
+ end
+ end
+
+ def connecting( u_header )
+ u_header = procheader( u_header )
+
+ if not @socket then
+ u_header['Connection'] = 'Close'
+ start
+ elsif @socket.closed? then
@socket.reopen
end
- header = yield
- @socket.close unless keep_alive? header
- header
+ yield
+
+ unless keep_alive? u_header then
+ @socket.close
+ end
end
def keep_alive?( header )
- if str = header[ 'connection' ] then
- if /\Aconnection:\s*keep-alive/i === str then
+ if str = header['Connection'] then
+ if /\A\s*keep-alive/i === str then
return true
end
else
- if @http_version == '1.1' then
+ if @command.http_version == '1.1' then
return true
end
end
@@ -102,14 +121,16 @@ class HTTPBadResponse < HTTPError; end
false
end
-
- def do_finish
- unless @command.error_occured or @socket.closed? then
- head '/', { 'Connection' => 'Close' }
+ def procheader( h )
+ new = {}
+ h.each do |k,v|
+ arr = k.split('-')
+ arr.each{|i| i.capitalize! }
+ new[ arr.join('-') ] = v
end
end
-
+
def edit_path( path )
path
end
@@ -148,7 +169,7 @@ class HTTPBadResponse < HTTPError; end
end
- attr :http_version
+ attr_reader :http_version
def get( ret, path, u_header = nil )
header = get_response(
@@ -195,12 +216,6 @@ class HTTPBadResponse < HTTPError; end
private
- def do_quit
- unless @socket.closed? then
- @socket.close
- end
- end
-
def get_response( line, u_header )
@socket.writeline line
write_header u_header
@@ -231,7 +246,7 @@ class HTTPBadResponse < HTTPError; end
when ?3 then RetryCode
when ?4 then ServerBusyCode
when ?5 then FatalErrorCode
- else UnknownCode
+ else UnknownCode
end
klass.new( status, discrip )
end