1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Version 1.1.4

o  (HTTP) allow no content-length data


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2000-01-21 12:52:24 +00:00
parent e5ed1780af
commit 005f125829
4 changed files with 39 additions and 28 deletions

View file

@ -57,8 +57,6 @@ class HTTPBadResponse < HTTPError; end
class HTTP < Protocol class HTTP < Protocol
Version = '1.1.3'
protocol_param :port, '80' protocol_param :port, '80'
protocol_param :command_type, '::Net::HTTPCommand' protocol_param :command_type, '::Net::HTTPCommand'
@ -143,7 +141,7 @@ class HTTPBadResponse < HTTPError; end
@in_header = {} @in_header = {}
@in_header[ 'Host' ] = sock.addr @in_header[ 'Host' ] = sock.addr
@in_header[ 'Connection' ] = 'keep-alive' @in_header[ 'Connection' ] = 'Keep-Alive'
@in_header[ 'Accept' ] = '*/*' @in_header[ 'Accept' ] = '*/*'
super sock super sock
@ -161,7 +159,11 @@ class HTTPBadResponse < HTTPError; end
header.delete 'transfer-encoding' header.delete 'transfer-encoding'
header[ 'content-length' ] = "Content-Length: #{clen}" header[ 'content-length' ] = "Content-Length: #{clen}"
else else
@socket.read content_length( header ), ret if clen = content_length( header ) then
@socket.read clen, ret
else
@socket.read_all ret
end
end end
header header
@ -229,10 +231,10 @@ class HTTPBadResponse < HTTPError; end
def content_length( header ) def content_length( header )
unless str = header[ 'content-length' ] then unless str = header[ 'content-length' ] then
raise HTTPBadResponce, "content-length not given" return nil
end end
unless /\Acontent-length:\s*(\d+)/i === str then unless /\Acontent-length:\s*(\d+)/i === str then
raise HTTPBadResponce, "content-length format error" raise HTTPBadResponse, "content-length format error"
end end
$1.to_i $1.to_i
end end
@ -289,7 +291,7 @@ class HTTPBadResponse < HTTPError; end
while true do while true do
line = @socket.readline line = @socket.readline
unless /[0-9a-hA-H]+/ === line then unless /[0-9a-hA-H]+/ === line then
raise HTTPBadResponce, "chunk size not given" raise HTTPBadResponse, "chunk size not given"
end end
len = $&.hex len = $&.hex
break if len == 0 break if len == 0

View file

@ -48,8 +48,6 @@ Net::Protocol
class POP3 < Protocol class POP3 < Protocol
Version = '1.1.3'
protocol_param :port, '110' protocol_param :port, '110'
protocol_param :command_type, '::Net::POP3Command' protocol_param :command_type, '::Net::POP3Command'

View file

@ -1,6 +1,6 @@
=begin =begin
= net/session.rb version 1.1.3 = net/session.rb
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp> written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
@ -15,6 +15,7 @@ require 'socket'
module Net module Net
Version = '1.1.4'
=begin =begin
@ -29,7 +30,7 @@ Object
=== Constants === Constants
: Version : Version
The version of Session class. It is a string like "1.1.3". The version of Session class. It is a string like "1.1.4".
=== Class Methods === Class Methods
@ -73,8 +74,6 @@ Object
class Protocol class Protocol
Version = '1.1.3'
class << self class << self
def start( address = 'localhost', port = nil, *args ) def start( address = 'localhost', port = nil, *args )
@ -470,7 +469,7 @@ Object
def reopen def reopen
unless closed? then unless closed? then
@socket.close @socket.close
flush_rbuf @buffer = ''
end end
@socket = TCPsocket.new( @addr, @port ) @socket = TCPsocket.new( @addr, @port )
end end
@ -511,25 +510,43 @@ Object
@pipe << "reading #{len} bytes...\n" if pre = @pipe ; @pipe = nil @pipe << "reading #{len} bytes...\n" if pre = @pipe ; @pipe = nil
rsize = 0 rsize = 0
while rsize + @buffer.size < len do while rsize + @buffer.size < len do
rsize += @buffer.size rsize += writeinto( ret, @buffer.size )
ret << fetch_rbuf( @buffer.size )
fill_rbuf fill_rbuf
end end
ret << fetch_rbuf( len - rsize ) writeinto( ret, len - rsize )
@pipe << "read #{len} bytes\n" if @pipe = pre @pipe << "read #{len} bytes\n" if @pipe = pre
ret ret
end end
def read_all( ret = '' )
@pipe << "reading all...\n" if pre = @pipe; @pipe = nil
rsize = 0
begin
while true do
rsize += writeinto( ret, @buffer.size )
fill_rbuf
end
rescue EOFError
;
end
@pipe << "read #{rsize} bytes\n" if @pipe = pre
ret
end
def readuntil( target ) def readuntil( target )
until idx = @buffer.index( target ) do until idx = @buffer.index( target ) do
fill_rbuf fill_rbuf
end end
fetch_rbuf( idx + target.size ) ret = ''
writeinto( ret, idx + target.size )
ret
end end
@ -583,17 +600,13 @@ Object
@buffer << @socket.sysread( READ_BLOCK ) @buffer << @socket.sysread( READ_BLOCK )
end end
def fetch_rbuf( len ) def writeinto( ret, len )
bsi = @buffer.size bsi = @buffer.size
ret = @buffer[ 0, len ] ret << @buffer[ 0, len ]
@buffer = @buffer[ len, bsi - len ] @buffer = @buffer[ len, bsi - len ]
@pipe << %{read "#{Net.quote ret}"\n} if @pipe @pipe << %{read "#{Net.quote ret}"\n} if @pipe
ret len
end
def flush_rbuf
@buffer = ''
end end

View file

@ -55,8 +55,6 @@ Net::Protocol
class SMTP < Protocol class SMTP < Protocol
Version = '1.1.3'
protocol_param :port, '25' protocol_param :port, '25'
protocol_param :command_type, '::Net::SMTPCommand' protocol_param :command_type, '::Net::SMTPCommand'