summaryrefslogtreecommitdiff
path: root/lib
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
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')
-rw-r--r--lib/net/http.rb85
-rw-r--r--lib/net/protocol.rb27
2 files changed, 70 insertions, 42 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index d925470171..2f5d76cc26 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
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 9e97beec5a..7eb38cf993 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -64,6 +64,14 @@ require 'timeout'
module Net
+ module NetPrivate
+ end
+
+ def self.net_private( &block )
+ ::Net::NetPrivate.module_eval( &block )
+ end
+
+
class Protocol
Version = '1.2.0'
@@ -232,6 +240,7 @@ module Net
Session = Protocol
+ net_private {
class Response
@@ -255,6 +264,8 @@ module Net
end
+ }
+
class ProtocolError < StandardError; end
class ProtoSyntaxError < ProtocolError; end
@@ -326,8 +337,7 @@ module Net
- module NetPrivate
-
+ net_private {
class WriteAdapter
@@ -496,12 +506,14 @@ module Net
"#<#{type} open=#{!@closed}>"
end
- def reopen
+ def reopen( otime = nil )
unless closed? then
close
@buffer = ''
end
- @socket = TCPsocket.new( @addr, @port )
+ timeout( otime ) {
+ @socket = TCPsocket.new( @addr, @port )
+ }
@closed = false
end
@@ -676,7 +688,7 @@ module Net
def write_bin( src, block )
writing {
if block then
- block.call WriteAdapter.new( self, :do_write )
+ block.call ::Net::NetPrivate::WriteAdapter.new( self, :do_write )
else
src.each do |bin|
do_write bin
@@ -690,7 +702,7 @@ module Net
wsize = use_each_crlf_line {
if block then
- block.call WriteAdapter.new( self, :wpend_in )
+ block.call ::Net::NetPrivate::WriteAdapter.new( self, :wpend_in )
else
wpend_in src
end
@@ -830,8 +842,7 @@ module Net
end
-
- end # module Net::NetPrivate
+ }
def Net.quote( str )