1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
aamine 2001-02-07 07:23:09 +00:00
parent bf5ea58942
commit 7e5f9d5a13
3 changed files with 79 additions and 42 deletions

View file

@ -1,3 +1,12 @@
Wed Feb 7 16:27:27 2001 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
* 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.
Tue Feb 6 21:30:44 2001 Minero Aoki <aamine@dp.u-netsurf.ne.jp> Tue Feb 6 21:30:44 2001 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
* lib/net/http.rb: call on_connect() on re-opening socket. * lib/net/http.rb: call on_connect() on re-opening socket.

View file

@ -221,6 +221,11 @@ module Net
def do_finish def do_finish
end end
def re_connect
@socket.reopen @open_timeout
on_connect
end
### ###
### proxy ### proxy
@ -425,8 +430,7 @@ module Net
start start
req['connection'] = 'close' req['connection'] = 'close'
elsif @socket.closed? then elsif @socket.closed? then
@socket.reopen re_connect
on_connect
end end
if @seems_1_0_server then if @seems_1_0_server then
req['connection'] = 'close' req['connection'] = 'close'
@ -553,12 +557,12 @@ module Net
class HTTP
### ###
### request ### request
### ###
net_private {
class HTTPRequest class HTTPRequest
def initialize( path, uhead = nil ) def initialize( path, uhead = nil )
@ -578,8 +582,6 @@ module Net
@http_version = nil @http_version = nil
end end
public
attr_reader :path attr_reader :path
attr_reader :response attr_reader :response
attr_reader :http_version attr_reader :http_version
@ -616,7 +618,8 @@ module Net
@u_header.each_value( &block ) @u_header.each_value( &block )
end end
private
private
def canonical( k ) def canonical( k )
k.split('-').collect {|i| i.capitalize }.join('-') k.split('-').collect {|i| i.capitalize }.join('-')
@ -637,7 +640,7 @@ module Net
@socket = sock @socket = sock
ihead.update @u_header ihead.update @u_header
yield ihead yield ihead
@response = read_response @response = get_response
@sock = nil @sock = nil
end end
@ -653,13 +656,20 @@ module Net
# read # read
# #
def read_response def get_response
resp = rdresp0 begin
resp = rdresp0 while ContinueCode === resp resp = read_response
end while ContinueCode === resp
resp resp
end end
def rdresp0 end
module HTTPReadResponse
private
def read_response
resp = get_resline resp = get_resline
while true do while true do
@ -694,13 +704,17 @@ module Net
::Net::NetPrivate::HTTPResponse.new( ::Net::NetPrivate::HTTPResponse.new(
status, discrip, @socket, type::HAS_BODY ) status, discrip, @socket, type::HAS_BODY )
end end
end
class HTTPRequest
include ::Net::NetPrivate::HTTPReadResponse
end end
class HTTPRequestWithData < HTTPRequest class HTTPRequestWithData < HTTPRequest
private private
def exec( sock, ver, path, ihead, str = nil ) def exec( sock, ver, path, ihead, str = nil )
check_arg str, block_given? check_arg str, block_given?
@ -753,37 +767,41 @@ module Net
end end
}
class Get < HTTPRequest
HAS_BODY = true
METHOD = 'GET'
end
class Head < HTTPRequest class HTTP
HAS_BODY = false
METHOD = 'HEAD'
end
class Post < HTTPRequestWithData class Get < ::Net::NetPrivate::HTTPRequest
HAS_BODY = true HAS_BODY = true
METHOD = 'POST' METHOD = 'GET'
end end
class Put < HTTPRequestWithData class Head < ::Net::NetPrivate::HTTPRequest
HAS_BODY = true HAS_BODY = false
METHOD = 'PUT' METHOD = 'HEAD'
end end
class Post < ::Net::NetPrivate::HTTPRequestWithData
HAS_BODY = true
METHOD = 'POST'
end
class Put < ::Net::NetPrivate::HTTPRequestWithData
HAS_BODY = true
METHOD = 'PUT'
end
end # HTTP:: end # HTTP::
module NetPrivate
### ###
### response ### response
### ###
net_private {
class HTTPResponse < Response class HTTPResponse < Response
HTTPCODE_CLASS_TO_OBJ = { HTTPCODE_CLASS_TO_OBJ = {
@ -1027,7 +1045,7 @@ module Net
'both of arg and block are given for HTTP method' 'both of arg and block are given for HTTP method'
end end
if block then if block then
ReadAdapter.new block ::Net::NetPrivate::ReadAdapter.new block
else else
dest or '' dest or ''
end end
@ -1035,7 +1053,6 @@ module Net
end end
}
end # module Net::NetPrivate
end # module Net end # module Net

View file

@ -64,6 +64,14 @@ require 'timeout'
module Net module Net
module NetPrivate
end
def self.net_private( &block )
::Net::NetPrivate.module_eval( &block )
end
class Protocol class Protocol
Version = '1.2.0' Version = '1.2.0'
@ -232,6 +240,7 @@ module Net
Session = Protocol Session = Protocol
net_private {
class Response class Response
@ -255,6 +264,8 @@ module Net
end end
}
class ProtocolError < StandardError; end class ProtocolError < StandardError; end
class ProtoSyntaxError < ProtocolError; end class ProtoSyntaxError < ProtocolError; end
@ -326,8 +337,7 @@ module Net
module NetPrivate net_private {
class WriteAdapter class WriteAdapter
@ -496,12 +506,14 @@ module Net
"#<#{type} open=#{!@closed}>" "#<#{type} open=#{!@closed}>"
end end
def reopen def reopen( otime = nil )
unless closed? then unless closed? then
close close
@buffer = '' @buffer = ''
end end
@socket = TCPsocket.new( @addr, @port ) timeout( otime ) {
@socket = TCPsocket.new( @addr, @port )
}
@closed = false @closed = false
end end
@ -676,7 +688,7 @@ module Net
def write_bin( src, block ) def write_bin( src, block )
writing { writing {
if block then if block then
block.call WriteAdapter.new( self, :do_write ) block.call ::Net::NetPrivate::WriteAdapter.new( self, :do_write )
else else
src.each do |bin| src.each do |bin|
do_write bin do_write bin
@ -690,7 +702,7 @@ module Net
wsize = use_each_crlf_line { wsize = use_each_crlf_line {
if block then if block then
block.call WriteAdapter.new( self, :wpend_in ) block.call ::Net::NetPrivate::WriteAdapter.new( self, :wpend_in )
else else
wpend_in src wpend_in src
end end
@ -830,8 +842,7 @@ module Net
end end
}
end # module Net::NetPrivate
def Net.quote( str ) def Net.quote( str )