diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-11-07 11:27:16 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-11-07 11:27:16 +0000 |
commit | 41e41d34d14ef3595a54148368b89b6c75d0fe4d (patch) | |
tree | ccbe4dd866bfcaeb2bc493b0938578746cd531f7 | |
parent | faeb1701cea992f5fb98c6d6c543e62f260b31c2 (diff) | |
download | ruby-41e41d34d14ef3595a54148368b89b6c75d0fe4d.tar.gz |
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
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | lib/net/http.rb | 152 | ||||
-rw-r--r-- | lib/net/pop.rb | 2 | ||||
-rw-r--r-- | lib/net/protocol.rb | 8 | ||||
-rw-r--r-- | lib/net/smtp.rb | 4 |
5 files changed, 104 insertions, 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 diff --git a/lib/net/http.rb b/lib/net/http.rb index bf6cf981e4..13135d13d9 100644 --- a/lib/net/http.rb +++ b/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 - end - end_critical - 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 + 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 - @socket.writeline '' + @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 - 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'] ) diff --git a/lib/net/pop.rb b/lib/net/pop.rb index 4eacb516d0..0a5dd2bc6e 100644 --- a/lib/net/pop.rb +++ b/lib/net/pop.rb @@ -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> diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 8aca2ef2d6..e070d29d99 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -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 diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index 33fc41e42a..6136cf0011 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -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 |