diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-02-06 11:57:09 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-02-06 11:57:09 +0000 |
commit | ab65e3df29b8915cbf6c09ac3f8617b6392e3eb8 (patch) | |
tree | 76f6b510679372f997ed6b4c16ed3a44c3c0b920 | |
parent | c9d8c38153b9b9a393da8e36b49be29514ed6412 (diff) |
aamine
* lib/net/protocol.rb: ignore EOFError on only specified case.
* lib/net/http.rb: take HTTP 1.0 server into account.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/net/http.rb | 27 | ||||
-rw-r--r-- | lib/net/protocol.rb | 9 |
3 files changed, 31 insertions, 11 deletions
@@ -1,3 +1,9 @@ +Tue Feb 6 21:01:29 2001 Minero Aoki <[email protected]> + + * lib/net/protocol.rb: ignore EOFError on only specified case. + + * lib/net/http.rb: take HTTP 1.0 server into account. + Fri Feb 3 00:48:50 2001 Usaku Nakamura <[email protected]> * win32/win32.c (isInternalCmd): ignore case for shell's internal diff --git a/lib/net/http.rb b/lib/net/http.rb index 3900ed6c68..e17967e064 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -432,6 +432,14 @@ module Net private + def do_start + @seems_1_0 = false + end + + def do_finish + end + + def common_oper( u_header, body_exist, block ) header = procheader( u_header ) recv = err = nil @@ -460,10 +468,18 @@ module Net elsif @socket.closed? then @socket.reopen end + if @seems_1_0 then + header['Connection'] = 'close' + end resp = yield - unless keep_alive? header, resp then + if keep_alive? header, resp then + if @socket.closed? then + @seems_1_0 = true + @socket.close + end + else @socket.close end end @@ -511,10 +527,6 @@ module Net ret end - - def do_finish - end - end HTTPSession = HTTP @@ -864,7 +876,8 @@ module Net resp = get_reply while true do - line = @socket.readline + line = @socket.readuntil( "\n", true ) # ignore EOF + line.sub!( /\s+\z/, '' ) # don't use chop! break if line.empty? m = /\A([^:]+):\s*/.match( line ) @@ -964,7 +977,7 @@ module Net else clen = content_length( resp ) if clen then - @socket.read clen, dest + @socket.read clen, dest, true else clen = range_length( resp ) if clen then diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index b9fa49971a..bfd15e71de 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -500,7 +500,7 @@ module Net CRLF = "\r\n" - def read( len, dest = '' ) + def read( len, dest = '', igneof = false ) @pipe << "reading #{len} bytes...\n" if @pipe; pipeoff rsize = 0 @@ -509,10 +509,10 @@ module Net rsize += writeinto( dest, @buffer.size ) fill_rbuf end + writeinto( dest, len - rsize ) rescue EOFError - len = rsize + raise unless igneof end - writeinto( dest, len - rsize ) @pipe << "read #{len} bytes\n" if pipeon dest @@ -537,7 +537,7 @@ module Net end - def readuntil( target ) + def readuntil( target, igneof = false ) dest = '' begin while true do @@ -547,6 +547,7 @@ module Net end writeinto( dest, idx + target.size ) rescue EOFError + raise unless igneof writeinto( dest, @buffer.size ) end dest |