mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Version 1.1.1
o HTTP chunk data git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1f7ea56df0
commit
47f58037b6
4 changed files with 51 additions and 10 deletions
|
@ -19,7 +19,7 @@ class HTTPBadResponse < HTTPError; end
|
||||||
|
|
||||||
class HTTPSession < Session
|
class HTTPSession < Session
|
||||||
|
|
||||||
Version = '1.1.0'
|
Version = '1.1.1'
|
||||||
|
|
||||||
session_setvar :port, '80'
|
session_setvar :port, '80'
|
||||||
session_setvar :command_type, 'HTTPCommand'
|
session_setvar :command_type, 'HTTPCommand'
|
||||||
|
@ -61,8 +61,8 @@ class HTTPCommand < Command
|
||||||
@in_header = {}
|
@in_header = {}
|
||||||
@in_header[ 'Host' ] = sock.addr
|
@in_header[ 'Host' ] = sock.addr
|
||||||
#@in_header[ 'User-Agent' ] = "Ruby http version #{HTTPSession::Version}"
|
#@in_header[ 'User-Agent' ] = "Ruby http version #{HTTPSession::Version}"
|
||||||
#@in_header[ 'Connection' ] = 'Keep-Alive'
|
@in_header[ 'Connection' ] = 'Keep-Alive'
|
||||||
#@in_header[ 'Accept' ] = '*/*'
|
@in_header[ 'Accept' ] = '*/*'
|
||||||
|
|
||||||
super sock
|
super sock
|
||||||
end
|
end
|
||||||
|
@ -75,7 +75,13 @@ class HTTPCommand < Command
|
||||||
write_header u_header
|
write_header u_header
|
||||||
check_reply SuccessCode
|
check_reply SuccessCode
|
||||||
header = read_header
|
header = read_header
|
||||||
@socket.read content_length( header ), ret
|
if chunked? header then
|
||||||
|
clen = read_chunked_body( ret )
|
||||||
|
header.delete 'transfer-encoding'
|
||||||
|
header[ 'content-length' ] = "Content-Length: #{clen}"
|
||||||
|
else
|
||||||
|
@socket.read content_length( header ), ret
|
||||||
|
end
|
||||||
@socket.close unless keep_alive? header
|
@socket.close unless keep_alive? header
|
||||||
|
|
||||||
return header, ret
|
return header, ret
|
||||||
|
@ -140,7 +146,7 @@ class HTTPCommand < Command
|
||||||
unless str = header[ 'content-length' ] then
|
unless str = header[ 'content-length' ] then
|
||||||
raise HTTPBadResponce, "content-length not given"
|
raise HTTPBadResponce, "content-length not given"
|
||||||
end
|
end
|
||||||
unless /content-length:\s*(\d+)/i === str then
|
unless /\Acontent-length:\s*(\d+)/i === str then
|
||||||
raise HTTPBadResponce, "content-length format error"
|
raise HTTPBadResponce, "content-length format error"
|
||||||
end
|
end
|
||||||
$1.to_i
|
$1.to_i
|
||||||
|
@ -148,7 +154,7 @@ class HTTPCommand < Command
|
||||||
|
|
||||||
def keep_alive?( header )
|
def keep_alive?( header )
|
||||||
if str = header[ 'connection' ] then
|
if str = header[ 'connection' ] then
|
||||||
if /connection:\s*keep-alive/i === str then
|
if /\Aconnection:\s*keep-alive/i === str then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -160,6 +166,16 @@ class HTTPCommand < Command
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def chunked?( header )
|
||||||
|
if str = header[ 'transfer-encoding' ] then
|
||||||
|
if /\Atransfer-encoding:\s*chunked/i === str then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def read_header
|
def read_header
|
||||||
header = {}
|
header = {}
|
||||||
|
@ -194,6 +210,29 @@ class HTTPCommand < Command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_chunked_body( ret )
|
||||||
|
line = nil
|
||||||
|
len = nil
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
while true do
|
||||||
|
line = @socket.readline
|
||||||
|
unless /[0-9a-hA-H]+/ === line then
|
||||||
|
raise HTTPBadResponce, "chunk size not given"
|
||||||
|
end
|
||||||
|
len = $&.hex
|
||||||
|
break if len == 0
|
||||||
|
@socket.read( len, ret ); total += len
|
||||||
|
@socket.read 2 # \r\n
|
||||||
|
end
|
||||||
|
while true do
|
||||||
|
line = @socket.readline
|
||||||
|
break if line.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
total
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,8 @@ Net::Session
|
||||||
|
|
||||||
class POP3Session < Session
|
class POP3Session < Session
|
||||||
|
|
||||||
|
Version = '1.1.1'
|
||||||
|
|
||||||
session_setvar :port, '110'
|
session_setvar :port, '110'
|
||||||
session_setvar :command_type, 'POP3Command'
|
session_setvar :command_type, 'POP3Command'
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/session.rb version 1.1.0
|
= net/session.rb version 1.1.1
|
||||||
|
|
||||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ Object
|
||||||
|
|
||||||
: Version
|
: Version
|
||||||
|
|
||||||
The version of Session class. It is a string like "1.1.0".
|
The version of Session class. It is a string like "1.1.1".
|
||||||
|
|
||||||
|
|
||||||
=== Class Methods
|
=== Class Methods
|
||||||
|
@ -77,7 +77,7 @@ Object
|
||||||
|
|
||||||
class Session
|
class Session
|
||||||
|
|
||||||
Version = '1.1.0'
|
Version = '1.1.1'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ Net::Session
|
||||||
|
|
||||||
class SMTPSession < Session
|
class SMTPSession < Session
|
||||||
|
|
||||||
Version = '1.1.0'
|
Version = '1.1.1'
|
||||||
|
|
||||||
session_setvar :port, '25'
|
session_setvar :port, '25'
|
||||||
session_setvar :command_type, 'SMTPCommand'
|
session_setvar :command_type, 'SMTPCommand'
|
||||||
|
|
Loading…
Reference in a new issue