diff --git a/ChangeLog b/ChangeLog index 51a78db2e1..c7f0c621b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Feb 6 21:01:29 2001 Minero Aoki + + * 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 * 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