From 0dcf7498b10c7fd4739b34236502efd8e0f8353c Mon Sep 17 00:00:00 2001 From: aamine Date: Sun, 26 Mar 2000 16:29:02 +0000 Subject: [PATCH] o http.rb: return value of 'head' was wrong git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/http.rb | 38 +++++++++++++++++++++----------------- lib/net/protocol.rb | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index bdbcb82fd5..14f9da4003 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -89,7 +89,7 @@ class HTTPBadResponse < HTTPError; end def get( path, u_header = nil, dest = nil, &block ) - u_header ||= {} + u_header = procheader( u_header ) if block then dest = ReadAdapter.new( block ) ret = nil @@ -106,7 +106,8 @@ class HTTPBadResponse < HTTPError; end return resp['http-header'], ret end - def get2( path, u_header = {} ) + def get2( path, u_header = nil ) + u_header = procheader( u_header ) only_header( :get, path, u_header ) end @@ -120,14 +121,15 @@ class HTTPBadResponse < HTTPError; end dest end - def head( path, u_header = {} ) - ret = only_header( :head, path, u_header )['http-header'] + def head( path, u_header = nil ) + u_header = procheader( u_header ) + header = only_header( :head, path, u_header ) ensure_termination u_header - ret + header end def post( path, data, u_header = nil, dest = nil, &block ) - u_header ||= {} + u_header = procheader( u_header ) if block then dest = ReadAdapter.new( block ) ret = nil @@ -145,12 +147,13 @@ class HTTPBadResponse < HTTPError; end end def post2( path, data, u_header = {} ) + u_header = procheader( u_header ) only_header :post, path, u_header, data end # not tested because I could not setup apache (__;;; - def put( path, src = nil, u_header = {}, &block ) - u_header ||= u_header + def put( path, src = nil, u_header = nil, &block ) + u_header = procheader( u_header ) connecting( u_header, true ) { @command.put path, u_header, src, dest } @@ -163,13 +166,13 @@ class HTTPBadResponse < HTTPError; end def only_header( mid, path, u_header, data = nil ) - @u_header = u_header ? procheader(u_header) : {} + @u_header = u_header @response = nil - ensure_connection @u_header + ensure_connection u_header if data then - @command.send mid, edit_path(path), @u_header, data + @command.send mid, edit_path(path), u_header, data else - @command.send mid, edit_path(path), @u_header + @command.send mid, edit_path(path), u_header end @response = @command.get_response @response['http-header'] @@ -187,7 +190,6 @@ class HTTPBadResponse < HTTPError; end end def connecting( u_header, putp = false ) - u_header = procheader( u_header ) ensure_connection u_header yield ensure_termination u_header @@ -203,7 +205,7 @@ class HTTPBadResponse < HTTPError; end end def ensure_termination( u_header ) - unless keep_alive? u_header then + unless keep_alive? u_header and not @socket.closed? then @socket.close end @u_header = @response = nil @@ -224,6 +226,7 @@ class HTTPBadResponse < HTTPError; end end def procheader( h ) + return( {} ) unless h new = {} h.each do |k,v| arr = k.split('-') @@ -339,10 +342,11 @@ class HTTPBadResponse < HTTPError; end if clen = content_length( header ) then @socket.read clen, dest else - ### - ### "multipart/bytelenges" check should be done here ... - ### + ##### "multipart/byteranges" check should be done here ... + + # now, length is designated by closing socket @socket.read_all dest + @socket.close end end end diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 3a200d5d29..4f2bf17fd4 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -15,7 +15,7 @@ require 'socket' module Net - Version = '1.1.9' + Version = '1.1.10' =begin