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

* lib/net/protocol.rb: set read_timeout dynamically.

* lib/net/http.rb: @@newimpl is always true in the main trunk.
* lib/net/http.rb: HTTP.port -> default_port
* lib/net/http.rb: HTTPResponse.read_response_status -> read_status_line


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2002-02-22 12:10:58 +00:00
parent 9093e4a4a5
commit d3b66ccf45
3 changed files with 48 additions and 39 deletions

View file

@ -1,3 +1,14 @@
Fri Feb 22 21:20:53 2002 Minero Aoki <aamine@loveruby.net>
* lib/net/protocol.rb: set read_timeout dynamically.
* lib/net/http.rb: @@newimpl is always true in the main trunk.
* lib/net/http.rb: HTTP.port -> default_port
* lib/net/http.rb: HTTPResponse.read_response_status ->
read_status_line
Fri Feb 22 19:56:15 2002 Usaku Nakamura <usa@ruby-lang.org>
* win32/config.status.in: set LIBRUBY_SO.

View file

@ -460,11 +460,7 @@ module Net
# for backward compatibility
#
if RUBY_VERSION <= '1.6' then
@@newimpl = false
else
@@newimpl = true
end
@@newimpl = true
def HTTP.version_1_2
@@newimpl = true
@ -492,7 +488,7 @@ module Net
def HTTP.get( addr, path, port = nil )
req = Get.new( path )
resp = nil
new( addr, port || HTTP.port ).start {|http|
new( addr, port || HTTP.default_port ).start {|http|
resp = http.request( req )
}
resp.body
@ -776,7 +772,7 @@ module Net
private
def addr_port
address + (port == HTTP.port ? '' : ":#{port}")
address + (port == HTTP.default_port ? '' : ":#{port}")
end
def D( msg )
@ -848,25 +844,19 @@ module Net
end
def range
s = @header['range']
s or return nil
arr = []
s.split(',').each do |spec|
m = /bytes\s*=\s*(\d+)?\s*-\s*(\d+)?/i.match( spec )
m or raise HTTPHeaderSyntaxError, "wrong Range: #{spec}"
d1 = m[1].to_i
d2 = m[2].to_i
if m[1] and m[2] then arr.push( d1..d2 )
elsif m[1] then arr.push( d1..-1 )
elsif m[2] then arr.push( -d2..-1 )
else
raise HTTPHeaderSyntaxError, 'range is not specified'
end
end
return arr
s = @header['range'] or return nil
s.split(',').collect {|spec|
m = /bytes\s*=\s*(\d+)?\s*-\s*(\d+)?/i.match(spec) or
raise HTTPHeaderSyntaxError, "wrong Range: #{spec}"
d1 = m[1].to_i
d2 = m[2].to_i
if m[1] and m[2] then d1..d2
elsif m[1] then d1..-1
elsif m[2] then -d2..-1
else
raise HTTPHeaderSyntaxError, 'range is not specified'
end
}
end
def range=( r, fin = nil )
@ -1279,19 +1269,26 @@ module Net
class << self
def read_new( sock, hasbody )
httpv, code, msg = read_response_status(sock)
httpv, code, msg = read_status_line(sock)
res = response_class(code).new( httpv, code, msg, sock, hasbody )
read_response_header sock, res
each_response_header(sock) do |k,v|
if res.key? k then
res[k] << ', ' << v
else
res[k] = v
end
end
res
end
private
def read_response_status( sock )
def read_status_line( sock )
str = sock.readline
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in.match(str) or
raise HTTPBadResponse, "wrong status line: #{str.dump}"
return m.to_a[1,3]
m.to_a[1,3]
end
def response_class( code )
@ -1300,7 +1297,7 @@ module Net
HTTPUnknownResponse
end
def read_response_header( sock, res )
def each_response_header( sock, res )
while true do
line = sock.readuntil( "\n", true ) # ignore EOF
line.sub!( /\s+\z/, '' ) # don't use chop!
@ -1308,13 +1305,7 @@ module Net
m = /\A([^:]+):\s*/.match(line) or
raise HTTPBadResponse, 'wrong header line format'
name = m[1]
line = m.post_match
if res.key? name then
res[name] << ', ' << line
else
res[name] = line
end
yield m[1], m.post_match
end
end

View file

@ -96,7 +96,12 @@ module Net
attr_reader :socket
attr_accessor :open_timeout
attr_accessor :read_timeout
attr_reader :read_timeout
def read_timeout=( sec )
@socket.read_timeout = sec if @socket
@read_timeout = sec
end
def active?
@active
@ -378,6 +383,8 @@ module Net
@socket.addr[3]
end
attr_accessor :read_timeout
attr_reader :socket
def connect( otime )