summaryrefslogtreecommitdiff
path: root/lib/net/http.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-07 07:23:09 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-07 07:23:09 +0000
commit7e5f9d5a137848b54fe6ab33caebb2631e613bf5 (patch)
treed906e0cbca08ee472d7397e9c5ba2074902e6cec /lib/net/http.rb
parentbf5ea589428d3a55174c773398fe49436fbac5d4 (diff)
aamine
* lib/net/http.rb: split HTTPResponse into HTTPReadResponse module. * lib/net/protocol.rb: add Net::net_private. * lib/net/protocol.rb: Socket#reopen takes arg, open_timeout. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r--lib/net/http.rb85
1 files changed, 51 insertions, 34 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index d925470..2f5d76c 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -221,6 +221,11 @@ module Net
def do_finish
end
+ def re_connect
+ @socket.reopen @open_timeout
+ on_connect
+ end
+
###
### proxy
@@ -425,8 +430,7 @@ module Net
start
req['connection'] = 'close'
elsif @socket.closed? then
- @socket.reopen
- on_connect
+ re_connect
end
if @seems_1_0_server then
req['connection'] = 'close'
@@ -553,12 +557,12 @@ module Net
- class HTTP
-
###
### request
###
+ net_private {
+
class HTTPRequest
def initialize( path, uhead = nil )
@@ -578,8 +582,6 @@ module Net
@http_version = nil
end
- public
-
attr_reader :path
attr_reader :response
attr_reader :http_version
@@ -616,7 +618,8 @@ module Net
@u_header.each_value( &block )
end
- private
+
+ private
def canonical( k )
k.split('-').collect {|i| i.capitalize }.join('-')
@@ -637,7 +640,7 @@ module Net
@socket = sock
ihead.update @u_header
yield ihead
- @response = read_response
+ @response = get_response
@sock = nil
end
@@ -653,13 +656,20 @@ module Net
# read
#
- def read_response
- resp = rdresp0
- resp = rdresp0 while ContinueCode === resp
+ def get_response
+ begin
+ resp = read_response
+ end while ContinueCode === resp
resp
end
- def rdresp0
+ end
+
+ module HTTPReadResponse
+
+ private
+
+ def read_response
resp = get_resline
while true do
@@ -694,13 +704,17 @@ module Net
::Net::NetPrivate::HTTPResponse.new(
status, discrip, @socket, type::HAS_BODY )
end
+
+ end
+ class HTTPRequest
+ include ::Net::NetPrivate::HTTPReadResponse
end
class HTTPRequestWithData < HTTPRequest
- private
+ private
def exec( sock, ver, path, ihead, str = nil )
check_arg str, block_given?
@@ -753,37 +767,41 @@ module Net
end
+ }
- class Get < HTTPRequest
- HAS_BODY = true
- METHOD = 'GET'
- end
- class Head < HTTPRequest
- HAS_BODY = false
- METHOD = 'HEAD'
- end
+ class HTTP
- class Post < HTTPRequestWithData
- HAS_BODY = true
- METHOD = 'POST'
- end
+ class Get < ::Net::NetPrivate::HTTPRequest
+ HAS_BODY = true
+ METHOD = 'GET'
+ end
- class Put < HTTPRequestWithData
- HAS_BODY = true
- METHOD = 'PUT'
- end
+ class Head < ::Net::NetPrivate::HTTPRequest
+ HAS_BODY = false
+ METHOD = 'HEAD'
+ end
- end # HTTP::
+ class Post < ::Net::NetPrivate::HTTPRequestWithData
+ HAS_BODY = true
+ METHOD = 'POST'
+ end
+
+ class Put < ::Net::NetPrivate::HTTPRequestWithData
+ HAS_BODY = true
+ METHOD = 'PUT'
+ end
+ end # HTTP::
- module NetPrivate
###
### response
###
+ net_private {
+
class HTTPResponse < Response
HTTPCODE_CLASS_TO_OBJ = {
@@ -1027,7 +1045,7 @@ module Net
'both of arg and block are given for HTTP method'
end
if block then
- ReadAdapter.new block
+ ::Net::NetPrivate::ReadAdapter.new block
else
dest or ''
end
@@ -1035,7 +1053,6 @@ module Net
end
-
- end # module Net::NetPrivate
+ }
end # module Net