{protocol,smtp,pop,http}.rb 1.1.15

o  http.rb: (keep_alive?)  use both user header and response
o  http.rb: (connecting)  returns response
o  http.rb: (connecting)  proc u_header and yield it
o  http.rb: (connecting)  call user block in conecting


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2000-04-22 07:29:53 +00:00
parent cb1b00b4b4
commit ee38413bf0
2 changed files with 39 additions and 57 deletions

View File

@ -70,6 +70,12 @@ module Net
"header" must be a Hash like { 'Accept' => '*/*', ... }. "header" must be a Hash like { 'Accept' => '*/*', ... }.
This method gives HTTPReadAdapter object to block. This method gives HTTPReadAdapter object to block.
: head2( path, header = nil )
send HEAD request for "path".
"header" must be a Hash like { 'Accept' => '*/*', ... }.
The difference between "head" method is that
"head2" does not raise exceptions.
: post2( path, data, header = nil ) {|adapter| .... } : post2( path, data, header = nil ) {|adapter| .... }
post "data"(must be String now) to "path". post "data"(must be String now) to "path".
"header" must be a Hash like { 'Accept' => '*/*', ... }. "header" must be a Hash like { 'Accept' => '*/*', ... }.
@ -145,17 +151,10 @@ All "key" is case-insensitive.
return resp, dest return resp, dest
end end
def get2( path, u_header = nil ) def get2( path, u_header = nil, &block )
u_header = procheader( u_header ) connecting( u_header, block ) {|uh|
resp = nil @command.get edit_path(path), uh
connecting( u_header ) {
@command.get edit_path(path), u_header
tmp = HTTPReadAdapter.new( @command )
yield tmp
resp = tmp.off
} }
resp
end end
@ -166,14 +165,10 @@ All "key" is case-insensitive.
end end
def head2( path, u_header = nil ) def head2( path, u_header = nil )
u_header = procheader( u_header ) connecting( u_header, nil ) {|uh|
resp = nil @command.head edit_path(path), uh
connecting( u_header ) { @command.get_response_no_body
@command.head( edit_path(path), u_header )
resp = @command.get_response_no_body
} }
resp
end end
@ -184,17 +179,10 @@ All "key" is case-insensitive.
return resp, dest return resp, dest
end end
def post2( path, data, u_header = nil ) def post2( path, data, u_header = nil, &block )
u_header = procheader( u_header ) connecting( u_header, block ) {|uh|
resp = nil @command.post edit_path(path), uh, data
connecting( u_header ) {
@command.post edit_path(path), u_header, data
tmp = HTTPReadAdapter.new( @command )
yield tmp
resp = tmp.off
} }
resp
end end
@ -206,18 +194,10 @@ All "key" is case-insensitive.
return resp, ret return resp, ret
end end
def put2( path, src, u_header = nil ) def put2( path, src, u_header = nil, &block )
u_header = procheader( u_header ) connecting( u_header, block ) {|uh|
ret = '' @command.put path, uh, src
resp = nil
connecting( u_header ) {
@command.put path, u_header, src, dest
tmp = HTTPReadAdapter.new( @command )
yield tmp
resp = tmp.off
} }
resp
end end
@ -227,38 +207,40 @@ All "key" is case-insensitive.
# called when connecting # called when connecting
def do_finish def do_finish
unless @socket.closed? then unless @socket.closed? then
begin head2 '/', { 'Connection' => 'close' }
@command.head '/', { 'Connection' => 'Close' }
rescue EOFError
end
end end
end end
def connecting( u_header ) def connecting( u_header, ublock )
u_header = procheader( u_header )
if not @socket then if not @socket then
u_header['Connection'] = 'Close' u_header['Connection'] = 'close'
start start
elsif @socket.closed? then elsif @socket.closed? then
@socket.reopen @socket.reopen
end end
if iterator? then resp = yield( u_header )
ret = yield if ublock then
ensure_termination u_header adapter = HTTPReadAdapter.new( @command )
ret ublock.call adapter
resp = adapter.off
end end
end
def ensure_termination( u_header ) unless keep_alive? u_header, resp then
unless keep_alive? u_header and not @socket.closed? then
@socket.close @socket.close
end end
@u_header = @response = nil
resp
end end
def keep_alive?( header ) def keep_alive?( header, resp )
if header.key? 'connection' then if resp.key? 'connection' then
if /\A\s*keep-alive/i === header['connection'] then if /keep-alive/i === resp['connection'] then
return true
end
elsif header.key? 'Connection' then
if /\A\s*keep-alive/i === header['Connection'] then
return true return true
end end
else else

View File

@ -15,7 +15,7 @@ require 'socket'
module Net module Net
Version = '1.1.14' Version = '1.1.15'
=begin =begin