From 877ac7236a8c509959eddc5add7ba0f10fae4804 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 8 Nov 2008 09:41:24 +0000 Subject: * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#do_CONNECT): use #bytesize instead of #size. a patch submitted from raspberry lemon in [ruby-core:18571]. * lib/webrick/httpauth/digestauth.rb, lib/webrick/httpproxy.rb, lib/webrick/httprequest.rb, lib/webrick/httpservlet/cgi_runner.rb, lib/webrick/httpservlet/abstract.rb, lib/webrick/httpresponse.rb, lib/webrick/httpservlet/cgihandler.rb, lib/webrick/utils.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httpauth/digestauth.rb | 2 +- lib/webrick/httpproxy.rb | 4 ++-- lib/webrick/httprequest.rb | 6 +++--- lib/webrick/httpresponse.rb | 20 ++++++++++---------- lib/webrick/httpservlet/abstract.rb | 2 +- lib/webrick/httpservlet/cgi_runner.rb | 2 +- lib/webrick/httpservlet/cgihandler.rb | 10 +++++----- lib/webrick/httpservlet/filehandler.rb | 4 ++-- lib/webrick/utils.rb | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/webrick/httpauth/digestauth.rb b/lib/webrick/httpauth/digestauth.rb index 9510c11d3b..eec064ca26 100644 --- a/lib/webrick/httpauth/digestauth.rb +++ b/lib/webrick/httpauth/digestauth.rb @@ -229,7 +229,7 @@ module WEBrick def split_param_value(string) ret = {} - while string.size != 0 + while string.bytesize != 0 case string when /^\s*([\w\-\.\*\%\!]+)=\s*\"((\\.|[^\"])*)\"\s*,?/ key = $1 diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb index 29ee1057e9..f35a177777 100644 --- a/lib/webrick/httpproxy.rb +++ b/lib/webrick/httpproxy.rb @@ -146,11 +146,11 @@ module WEBrick while fds = IO::select([ua, os]) if fds[0].member?(ua) buf = ua.sysread(1024); - @logger.debug("CONNECT: #{buf.size} byte from User-Agent") + @logger.debug("CONNECT: #{buf.bytesize} byte from User-Agent") os.syswrite(buf) elsif fds[0].member?(os) buf = os.sysread(1024); - @logger.debug("CONNECT: #{buf.size} byte from #{host}:#{port}") + @logger.debug("CONNECT: #{buf.bytesize} byte from #{host}:#{port}") ua.syswrite(buf) end end diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index f0994ef253..889a83abe4 100644 --- a/lib/webrick/httprequest.rb +++ b/lib/webrick/httprequest.rb @@ -244,7 +244,7 @@ module WEBrick def read_request_line(socket) @request_line = read_line(socket, 1024) if socket - if @request_line.size >= 1024 and @request_line[-1, 1] != LF + if @request_line.bytesize >= 1024 and @request_line[-1, 1] != LF raise HTTPStatus::RequestURITooLarge end @request_time = Time.now @@ -307,7 +307,7 @@ module WEBrick while @remaining_size > 0 sz = [@buffer_size, @remaining_size].min break unless buf = read_data(socket, sz) - @remaining_size -= buf.size + @remaining_size -= buf.bytesize block.call(buf) end if @remaining_size > 0 && @socket.eof? @@ -334,7 +334,7 @@ module WEBrick chunk_size, = read_chunk_size(socket) while chunk_size > 0 data = read_data(socket, chunk_size) # read chunk-data - if data.nil? || data.size != chunk_size + if data.nil? || data.bytesize != chunk_size raise BadRequest, "bad chunk data size." end read_line(socket) # skip CRLF diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb index 301ecb8372..740a8fe921 100644 --- a/lib/webrick/httpresponse.rb +++ b/lib/webrick/httpresponse.rb @@ -142,7 +142,7 @@ module WEBrick @header.delete('content-length') elsif @header['content-length'].nil? unless @body.is_a?(IO) - @header['content-length'] = @body ? @body.size : 0 + @header['content-length'] = @body ? @body.bytesize : 0 end end @@ -260,10 +260,10 @@ module WEBrick while buf = @body.read(@buffer_size) next if buf.empty? data = "" - data << format("%x", buf.size) << CRLF + data << format("%x", buf.bytesize) << CRLF data << buf << CRLF _write_data(socket, data) - @sent_size += buf.size + @sent_size += buf.bytesize end _write_data(socket, "0#{CRLF}#{CRLF}") else @@ -280,20 +280,20 @@ module WEBrick if @request_method == "HEAD" # do nothing elsif chunked? - remain = body ? @body.size : 0 + remain = body ? @body.bytesize : 0 while buf = @body[@sent_size, @buffer_size] break if buf.empty? data = "" - data << format("%x", buf.size) << CRLF + data << format("%x", buf.bytesize) << CRLF data << buf << CRLF _write_data(socket, data) - @sent_size += buf.size + @sent_size += buf.bytesize end _write_data(socket, "0#{CRLF}#{CRLF}") else - if @body && @body.size > 0 + if @body && @body.bytesize > 0 _write_data(socket, @body) - @sent_size = @body.size + @sent_size = @body.bytesize end end end @@ -302,7 +302,7 @@ module WEBrick while offset > 0 sz = @buffer_size < size ? @buffer_size : size buf = input.read(sz) - offset -= buf.size + offset -= buf.bytesize end if size == 0 @@ -314,7 +314,7 @@ module WEBrick sz = @buffer_size < size ? @buffer_size : size buf = input.read(sz) _write_data(output, buf) - size -= buf.size + size -= buf.bytesize end end end diff --git a/lib/webrick/httpservlet/abstract.rb b/lib/webrick/httpservlet/abstract.rb index 5375c4622d..2a0a4049f2 100644 --- a/lib/webrick/httpservlet/abstract.rb +++ b/lib/webrick/httpservlet/abstract.rb @@ -59,7 +59,7 @@ module WEBrick def redirect_to_directory_uri(req, res) if req.path[-1] != ?/ location = WEBrick::HTTPUtils.escape_path(req.path + "/") - if req.query_string && req.query_string.size > 0 + if req.query_string && req.query_string.bytesize > 0 location << "?" << req.query_string end res.set_redirect(HTTPStatus::MovedPermanently, location) diff --git a/lib/webrick/httpservlet/cgi_runner.rb b/lib/webrick/httpservlet/cgi_runner.rb index 006abd458e..dd7325d25c 100644 --- a/lib/webrick/httpservlet/cgi_runner.rb +++ b/lib/webrick/httpservlet/cgi_runner.rb @@ -13,7 +13,7 @@ def sysread(io, size) while size > 0 tmp = io.sysread(size) buf << tmp - size -= tmp.size + size -= tmp.bytesize end return buf end diff --git a/lib/webrick/httpservlet/cgihandler.rb b/lib/webrick/httpservlet/cgihandler.rb index 9211e95354..f504f4d63b 100644 --- a/lib/webrick/httpservlet/cgihandler.rb +++ b/lib/webrick/httpservlet/cgihandler.rb @@ -48,14 +48,14 @@ module WEBrick end dump = Marshal.dump(meta) - cgi_in.write("%8d" % cgi_out.path.size) + cgi_in.write("%8d" % cgi_out.path.bytesize) cgi_in.write(cgi_out.path) - cgi_in.write("%8d" % cgi_err.path.size) + cgi_in.write("%8d" % cgi_err.path.bytesize) cgi_in.write(cgi_err.path) - cgi_in.write("%8d" % dump.size) + cgi_in.write("%8d" % dump.bytesize) cgi_in.write(dump) - if req.body and req.body.size > 0 + if req.body and req.body.bytesize > 0 cgi_in.write(req.body) end ensure @@ -65,7 +65,7 @@ module WEBrick data = cgi_out.read cgi_out.close(true) if errmsg = cgi_err.read - if errmsg.size > 0 + if errmsg.bytesize > 0 @logger.error("CGIHandler: #{@script_filename}:\n" + errmsg) end end diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb index 272ffbc3fc..f1cc88bed9 100644 --- a/lib/webrick/httpservlet/filehandler.rb +++ b/lib/webrick/httpservlet/filehandler.rb @@ -407,13 +407,13 @@ module WEBrick list.each{ |name, time, size| if name == ".." dname = "Parent Directory" - elsif name.size > 25 + elsif name.bytesize > 25 dname = name.sub(/^(.{23})(?:.*)/, '\1..') else dname = name end s = " #{dname}" - s << " " * (30 - dname.size) + s << " " * (30 - dname.bytesize) s << (time ? time.strftime("%Y/%m/%d %H:%M ") : " " * 22) s << (size >= 0 ? size.to_s : "-") << "\n" res.body << s diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index 654abb28b1..f2ecfc19a8 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -89,7 +89,7 @@ module WEBrick "abcdefghijklmnopqrstuvwxyz" def random_string(len) - rand_max = RAND_CHARS.size + rand_max = RAND_CHARS.bytesize ret = "" len.times{ ret << RAND_CHARS[rand(rand_max)] } ret -- cgit v1.2.3