mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
aamine
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.30 * lib/net/protocol.rb, smtp.rb: Command#critical_ok -> error_ok * lib/net/http.rb: read header when also "100 Continue" git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
faeb1701ce
commit
41e41d34d1
5 changed files with 104 additions and 70 deletions
|
@ -1,3 +1,11 @@
|
|||
Tue Nov 7 20:29:56 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
|
||||
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.30
|
||||
|
||||
* lib/net/protocol.rb, smtp.rb: Command#critical_ok -> error_ok
|
||||
|
||||
* lib/net/http.rb: read header when also "100 Continue"
|
||||
|
||||
Thu Nov 2 18:01:16 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* random.c (rb_f_rand): half-baked float support fixed. This fix
|
||||
|
|
152
lib/net/http.rb
152
lib/net/http.rb
|
@ -1,6 +1,6 @@
|
|||
=begin
|
||||
|
||||
= net/http.rb version 1.1.29
|
||||
= net/http.rb version 1.1.30
|
||||
|
||||
maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
This file is derived from "http-access.rb".
|
||||
|
@ -670,6 +670,12 @@ SRC
|
|||
end
|
||||
|
||||
|
||||
###
|
||||
### request
|
||||
###
|
||||
|
||||
public
|
||||
|
||||
def get( path, u_header )
|
||||
return unless begin_critical
|
||||
request sprintf('GET %s HTTP/%s', path, HTTPVersion), u_header
|
||||
|
@ -703,9 +709,39 @@ SRC
|
|||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def request( req, u_header )
|
||||
@socket.writeline req
|
||||
if u_header then
|
||||
header = @in_header.dup.update( u_header )
|
||||
else
|
||||
header = @in_header
|
||||
end
|
||||
header.each do |n,v|
|
||||
@socket.writeline n + ': ' + v
|
||||
end
|
||||
@socket.writeline ''
|
||||
end
|
||||
|
||||
|
||||
###
|
||||
### response line & header
|
||||
###
|
||||
|
||||
public
|
||||
|
||||
def get_response
|
||||
resp = get_resp0
|
||||
resp = get_resp0 while ContinueCode === resp
|
||||
resp
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def get_resp0
|
||||
resp = get_reply
|
||||
resp = get_reply while ContinueCode === resp
|
||||
|
||||
while true do
|
||||
line = @socket.readline
|
||||
|
@ -727,56 +763,22 @@ SRC
|
|||
resp
|
||||
end
|
||||
|
||||
|
||||
def get_body( resp, dest )
|
||||
if chunked? resp then
|
||||
read_chunked( dest, resp )
|
||||
else
|
||||
clen = content_length( resp )
|
||||
if clen then
|
||||
@socket.read clen, dest
|
||||
else
|
||||
clen = range_length( resp )
|
||||
if clen then
|
||||
@socket.read clen, dest
|
||||
else
|
||||
tmp = resp['connection']
|
||||
if tmp and /close/i === tmp then
|
||||
@socket.read_all dest
|
||||
else
|
||||
tmp = resp['proxy-connection']
|
||||
if tmp and /close/i === tmp then
|
||||
@socket.read_all dest
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_reply
|
||||
str = @socket.readline
|
||||
m = /\AHTTP\/(\d+\.\d+)?\s+(\d\d\d)\s*(.*)\z/i.match( str )
|
||||
unless m then
|
||||
raise HTTPBadResponse, "wrong status line: #{str}"
|
||||
end
|
||||
end_critical
|
||||
@http_version = m[1]
|
||||
status = m[2]
|
||||
discrip = m[3]
|
||||
|
||||
code = HTTPCODE_TO_OBJ[status] ||
|
||||
HTTPCODE_CLASS_TO_OBJ[status[0,1]] ||
|
||||
UnknownCode
|
||||
HTTPResponse.new( code, status, discrip )
|
||||
end
|
||||
|
||||
def no_body
|
||||
end_critical
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def request( req, u_header )
|
||||
@socket.writeline req
|
||||
if u_header then
|
||||
header = @in_header.dup.update( u_header )
|
||||
else
|
||||
header = @in_header
|
||||
end
|
||||
header.each do |n,v|
|
||||
@socket.writeline n + ': ' + v
|
||||
end
|
||||
@socket.writeline ''
|
||||
end
|
||||
|
||||
|
||||
HTTPCODE_CLASS_TO_OBJ = {
|
||||
'1' => HTTPInformationCode,
|
||||
'2' => HTTPSuccessCode,
|
||||
|
@ -829,22 +831,47 @@ SRC
|
|||
'505' => HTTPVersionNotSupported
|
||||
}
|
||||
|
||||
def get_reply
|
||||
str = @socket.readline
|
||||
m = /\AHTTP\/(\d+\.\d+)?\s+(\d\d\d)\s*(.*)\z/i.match( str )
|
||||
unless m then
|
||||
raise HTTPBadResponse, "wrong status line: #{str}"
|
||||
|
||||
###
|
||||
### body
|
||||
###
|
||||
|
||||
public
|
||||
|
||||
def get_body( resp, dest )
|
||||
if chunked? resp then
|
||||
read_chunked( dest, resp )
|
||||
else
|
||||
clen = content_length( resp )
|
||||
if clen then
|
||||
@socket.read clen, dest
|
||||
else
|
||||
clen = range_length( resp )
|
||||
if clen then
|
||||
@socket.read clen, dest
|
||||
else
|
||||
tmp = resp['connection']
|
||||
if tmp and /close/i === tmp then
|
||||
@socket.read_all dest
|
||||
else
|
||||
tmp = resp['proxy-connection']
|
||||
if tmp and /close/i === tmp then
|
||||
@socket.read_all dest
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@http_version = m[1]
|
||||
status = m[2]
|
||||
discrip = m[3]
|
||||
|
||||
code = HTTPCODE_TO_OBJ[status] ||
|
||||
HTTPCODE_CLASS_TO_OBJ[status[0,1]] ||
|
||||
UnknownCode
|
||||
HTTPResponse.new( code, status, discrip )
|
||||
end_critical
|
||||
end
|
||||
|
||||
def no_body
|
||||
end_critical
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def read_chunked( ret, header )
|
||||
len = nil
|
||||
total = 0
|
||||
|
@ -865,7 +892,6 @@ SRC
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def content_length( header )
|
||||
if header.key? 'content-length' then
|
||||
m = /\d+/.match( header['content-length'] )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
=begin
|
||||
|
||||
= net/pop.rb version 1.1.29
|
||||
= net/pop.rb version 1.1.30
|
||||
|
||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
=begin
|
||||
|
||||
= net/protocol.rb version 1.1.29
|
||||
= net/protocol.rb version 1.1.30
|
||||
|
||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
|
||||
|
@ -69,7 +69,7 @@ module Net
|
|||
|
||||
class Protocol
|
||||
|
||||
Version = '1.1.29'
|
||||
Version = '1.1.30'
|
||||
|
||||
|
||||
class << self
|
||||
|
@ -421,10 +421,10 @@ module Net
|
|||
@critical = false
|
||||
end
|
||||
|
||||
def critical_ok
|
||||
def error_ok
|
||||
@critical = false
|
||||
end
|
||||
public :critical_ok
|
||||
public :error_ok
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
=begin
|
||||
|
||||
= net/smtp.rb version 1.1.29
|
||||
= net/smtp.rb version 1.1.30
|
||||
|
||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
|
||||
|
@ -146,7 +146,7 @@ module Net
|
|||
rescue ProtocolError
|
||||
if @esmtp then
|
||||
@esmtp = false
|
||||
@command.critical_ok
|
||||
@command.error_ok
|
||||
retry
|
||||
else
|
||||
raise
|
||||
|
|
Loading…
Reference in a new issue