patch.diff
| lib/webrick/httpproxy.rb (working copy) | ||
|---|---|---|
| 146 | 146 |
while fds = IO::select([ua, os]) |
| 147 | 147 |
if fds[0].member?(ua) |
| 148 | 148 |
buf = ua.sysread(1024); |
| 149 |
@logger.debug("CONNECT: #{buf.size} byte from User-Agent")
|
|
| 149 |
@logger.debug("CONNECT: #{buf.bytesize} byte from User-Agent")
|
|
| 150 | 150 |
os.syswrite(buf) |
| 151 | 151 |
elsif fds[0].member?(os) |
| 152 | 152 |
buf = os.sysread(1024); |
| 153 |
@logger.debug("CONNECT: #{buf.size} byte from #{host}:#{port}")
|
|
| 153 |
@logger.debug("CONNECT: #{buf.bytesize} byte from #{host}:#{port}")
|
|
| 154 | 154 |
ua.syswrite(buf) |
| 155 | 155 |
end |
| 156 | 156 |
end |
| lib/webrick/httpservlet/filehandler.rb (working copy) | ||
|---|---|---|
| 27 | 27 |
def do_GET(req, res) |
| 28 | 28 |
st = File::stat(@local_path) |
| 29 | 29 |
mtime = st.mtime |
| 30 |
res['etag'] = sprintf("%x-%x-%x", st.ino, st.size, st.mtime.to_i)
|
|
| 30 |
res['etag'] = sprintf("%x-%x-%x", st.ino, st.bytesize, st.mtime.to_i)
|
|
| 31 | 31 | |
| 32 | 32 |
if not_modified?(req, res, mtime, res['etag']) |
| 33 | 33 |
res.body = '' |
| 34 | 34 |
raise HTTPStatus::NotModified |
| 35 | 35 |
elsif req['range'] |
| 36 |
make_partial_content(req, res, @local_path, st.size) |
|
| 36 |
make_partial_content(req, res, @local_path, st.bytesize)
|
|
| 37 | 37 |
raise HTTPStatus::PartialContent |
| 38 | 38 |
else |
| 39 | 39 |
mtype = HTTPUtils::mime_type(@local_path, @config[:MimeTypes]) |
| 40 | 40 |
res['content-type'] = mtype |
| 41 |
res['content-length'] = st.size |
|
| 41 |
res['content-length'] = st.bytesize
|
|
| 42 | 42 |
res['last-modified'] = mtime.httpdate |
| 43 | 43 |
res.body = open(@local_path, "rb") |
| 44 | 44 |
end |
| ... | ... | |
| 76 | 76 |
"Unrecognized range-spec: \"#{req['range']}\""
|
| 77 | 77 |
end |
| 78 | 78 |
open(filename, "rb"){|io|
|
| 79 |
if ranges.size > 1 |
|
| 79 |
if ranges.bytesize > 1
|
|
| 80 | 80 |
time = Time.now |
| 81 | 81 |
boundary = "#{time.sec}_#{time.usec}_#{Process::pid}"
|
| 82 | 82 |
body = '' |
| ... | ... | |
| 315 | 315 |
path = res.filename + basename |
| 316 | 316 |
if File.file?(path) |
| 317 | 317 |
return basename |
| 318 |
elsif langs.size > 0 |
|
| 318 |
elsif langs.bytesize > 0
|
|
| 319 | 319 |
req.accept_language.each{|lang|
|
| 320 | 320 |
path_with_lang = path + ".#{lang}"
|
| 321 | 321 |
if langs.member?(lang) && File.file?(path_with_lang) |
| ... | ... | |
| 369 | 369 |
elsif st.directory? |
| 370 | 370 |
[ name + "/", st.mtime, -1 ] |
| 371 | 371 |
else |
| 372 |
[ name, st.mtime, st.size ] |
|
| 372 |
[ name, st.mtime, st.bytesize ]
|
|
| 373 | 373 |
end |
| 374 | 374 |
} |
| 375 | 375 |
list.compact! |
| ... | ... | |
| 407 | 407 |
list.each{ |name, time, size|
|
| 408 | 408 |
if name == ".." |
| 409 | 409 |
dname = "Parent Directory" |
| 410 |
elsif name.size > 25 |
|
| 410 |
elsif name.bytesize > 25
|
|
| 411 | 411 |
dname = name.sub(/^(.{23})(?:.*)/, '\1..')
|
| 412 | 412 |
else |
| 413 | 413 |
dname = name |
| 414 | 414 |
end |
| 415 | 415 |
s = " <A HREF=\"#{HTTPUtils::escape(name)}\">#{dname}</A>"
|
| 416 |
s << " " * (30 - dname.size) |
|
| 416 |
s << " " * (30 - dname.bytesize)
|
|
| 417 | 417 |
s << (time ? time.strftime("%Y/%m/%d %H:%M ") : " " * 22)
|
| 418 | 418 |
s << (size >= 0 ? size.to_s : "-") << "\n" |
| 419 | 419 |
res.body << s |
| lib/webrick/httpservlet/cgihandler.rb (working copy) | ||
|---|---|---|
| 48 | 48 |
end |
| 49 | 49 |
dump = Marshal.dump(meta) |
| 50 | 50 | |
| 51 |
cgi_in.write("%8d" % cgi_out.path.size)
|
|
| 51 |
cgi_in.write("%8d" % cgi_out.path.bytesize)
|
|
| 52 | 52 |
cgi_in.write(cgi_out.path) |
| 53 |
cgi_in.write("%8d" % cgi_err.path.size)
|
|
| 53 |
cgi_in.write("%8d" % cgi_err.path.bytesize)
|
|
| 54 | 54 |
cgi_in.write(cgi_err.path) |
| 55 |
cgi_in.write("%8d" % dump.size)
|
|
| 55 |
cgi_in.write("%8d" % dump.bytesize)
|
|
| 56 | 56 |
cgi_in.write(dump) |
| 57 | 57 | |
| 58 |
if req.body and req.body.size > 0 |
|
| 58 |
if req.body and req.body.bytesize > 0
|
|
| 59 | 59 |
cgi_in.write(req.body) |
| 60 | 60 |
end |
| 61 | 61 |
ensure |
| ... | ... | |
| 65 | 65 |
data = cgi_out.read |
| 66 | 66 |
cgi_out.close(true) |
| 67 | 67 |
if errmsg = cgi_err.read |
| 68 |
if errmsg.size > 0 |
|
| 68 |
if errmsg.bytesize > 0
|
|
| 69 | 69 |
@logger.error("CGIHandler: #{@script_filename}:\n" + errmsg)
|
| 70 | 70 |
end |
| 71 | 71 |
end |
| lib/webrick/httpservlet/abstract.rb (working copy) | ||
|---|---|---|
| 59 | 59 |
def redirect_to_directory_uri(req, res) |
| 60 | 60 |
if req.path[-1] != ?/ |
| 61 | 61 |
location = WEBrick::HTTPUtils.escape_path(req.path + "/") |
| 62 |
if req.query_string && req.query_string.size > 0 |
|
| 62 |
if req.query_string && req.query_string.bytesize > 0
|
|
| 63 | 63 |
location << "?" << req.query_string |
| 64 | 64 |
end |
| 65 | 65 |
res.set_redirect(HTTPStatus::MovedPermanently, location) |
| lib/webrick/httpservlet/cgi_runner.rb (working copy) | ||
|---|---|---|
| 13 | 13 |
while size > 0 |
| 14 | 14 |
tmp = io.sysread(size) |
| 15 | 15 |
buf << tmp |
| 16 |
size -= tmp.size |
|
| 16 |
size -= tmp.bytesize
|
|
| 17 | 17 |
end |
| 18 | 18 |
return buf |
| 19 | 19 |
end |
| lib/webrick/httprequest.rb (working copy) | ||
|---|---|---|
| 244 | 244 | |
| 245 | 245 |
def read_request_line(socket) |
| 246 | 246 |
@request_line = read_line(socket, 1024) if socket |
| 247 |
if @request_line.size >= 1024 and @request_line[-1, 1] != LF |
|
| 247 |
if @request_line.bytesize >= 1024 and @request_line[-1, 1] != LF
|
|
| 248 | 248 |
raise HTTPStatus::RequestURITooLarge |
| 249 | 249 |
end |
| 250 | 250 |
@request_time = Time.now |
| ... | ... | |
| 284 | 284 |
elsif self["host"] |
| 285 | 285 |
pattern = /\A(#{URI::REGEXP::PATTERN::HOST})(?::(\d+))?\z/n
|
| 286 | 286 |
host, port = *self['host'].scan(pattern)[0] |
| 287 |
elsif @addr.size > 0 |
|
| 287 |
elsif @addr.bytesize > 0
|
|
| 288 | 288 |
host, port = @addr[2], @addr[1] |
| 289 | 289 |
else |
| 290 | 290 |
host, port = @config[:ServerName], @config[:Port] |
| ... | ... | |
| 307 | 307 |
while @remaining_size > 0 |
| 308 | 308 |
sz = [@buffer_size, @remaining_size].min |
| 309 | 309 |
break unless buf = read_data(socket, sz) |
| 310 |
@remaining_size -= buf.size |
|
| 310 |
@remaining_size -= buf.bytesize
|
|
| 311 | 311 |
block.call(buf) |
| 312 | 312 |
end |
| 313 | 313 |
if @remaining_size > 0 && @socket.eof? |
| ... | ... | |
| 334 | 334 |
chunk_size, = read_chunk_size(socket) |
| 335 | 335 |
while chunk_size > 0 |
| 336 | 336 |
data = read_data(socket, chunk_size) # read chunk-data |
| 337 |
if data.nil? || data.size != chunk_size |
|
| 337 |
if data.nil? || data.bytesize != chunk_size
|
|
| 338 | 338 |
raise BadRequest, "bad chunk data size." |
| 339 | 339 |
end |
| 340 | 340 |
read_line(socket) # skip CRLF |
| lib/webrick/httpresponse.rb (working copy) | ||
|---|---|---|
| 142 | 142 |
@header.delete('content-length')
|
| 143 | 143 |
elsif @header['content-length'].nil? |
| 144 | 144 |
unless @body.is_a?(IO) |
| 145 |
@header['content-length'] = @body ? @body.size : 0 |
|
| 145 |
@header['content-length'] = @body ? @body.bytesize : 0
|
|
| 146 | 146 |
end |
| 147 | 147 |
end |
| 148 | 148 | |
| ... | ... | |
| 260 | 260 |
while buf = @body.read(@buffer_size) |
| 261 | 261 |
next if buf.empty? |
| 262 | 262 |
data = "" |
| 263 |
data << format("%x", buf.size) << CRLF
|
|
| 263 |
data << format("%x", buf.bytesize) << CRLF
|
|
| 264 | 264 |
data << buf << CRLF |
| 265 | 265 |
_write_data(socket, data) |
| 266 |
@sent_size += buf.size |
|
| 266 |
@sent_size += buf.bytesize
|
|
| 267 | 267 |
end |
| 268 | 268 |
_write_data(socket, "0#{CRLF}#{CRLF}")
|
| 269 | 269 |
else |
| ... | ... | |
| 280 | 280 |
if @request_method == "HEAD" |
| 281 | 281 |
# do nothing |
| 282 | 282 |
elsif chunked? |
| 283 |
remain = body ? @body.size : 0 |
|
| 283 |
remain = body ? @body.bytesize : 0
|
|
| 284 | 284 |
while buf = @body[@sent_size, @buffer_size] |
| 285 | 285 |
break if buf.empty? |
| 286 | 286 |
data = "" |
| 287 |
data << format("%x", buf.size) << CRLF
|
|
| 287 |
data << format("%x", buf.bytesize) << CRLF
|
|
| 288 | 288 |
data << buf << CRLF |
| 289 | 289 |
_write_data(socket, data) |
| 290 |
@sent_size += buf.size |
|
| 290 |
@sent_size += buf.bytesize
|
|
| 291 | 291 |
end |
| 292 | 292 |
_write_data(socket, "0#{CRLF}#{CRLF}")
|
| 293 | 293 |
else |
| 294 |
if @body && @body.size > 0 |
|
| 294 |
if @body && @body.bytesize > 0
|
|
| 295 | 295 |
_write_data(socket, @body) |
| 296 |
@sent_size = @body.size |
|
| 296 |
@sent_size = @body.bytesize
|
|
| 297 | 297 |
end |
| 298 | 298 |
end |
| 299 | 299 |
end |
| ... | ... | |
| 302 | 302 |
while offset > 0 |
| 303 | 303 |
sz = @buffer_size < size ? @buffer_size : size |
| 304 | 304 |
buf = input.read(sz) |
| 305 |
offset -= buf.size |
|
| 305 |
offset -= buf.bytesize
|
|
| 306 | 306 |
end |
| 307 | 307 | |
| 308 | 308 |
if size == 0 |
| ... | ... | |
| 314 | 314 |
sz = @buffer_size < size ? @buffer_size : size |
| 315 | 315 |
buf = input.read(sz) |
| 316 | 316 |
_write_data(output, buf) |
| 317 |
size -= buf.size |
|
| 317 |
size -= buf.bytesize
|
|
| 318 | 318 |
end |
| 319 | 319 |
end |
| 320 | 320 |
end |
| lib/webrick/httpauth/digestauth.rb (working copy) | ||
|---|---|---|
| 229 | 229 | |
| 230 | 230 |
def split_param_value(string) |
| 231 | 231 |
ret = {}
|
| 232 |
while string.size != 0 |
|
| 232 |
while string.bytesize != 0
|
|
| 233 | 233 |
case string |
| 234 | 234 |
when /^\s*([\w\-\.\*\%\!]+)=\s*\"((\\.|[^\"])*)\"\s*,?/ |
| 235 | 235 |
key = $1 |
| lib/webrick/utils.rb (working copy) | ||
|---|---|---|
| 89 | 89 |
"abcdefghijklmnopqrstuvwxyz" |
| 90 | 90 | |
| 91 | 91 |
def random_string(len) |
| 92 |
rand_max = RAND_CHARS.size |
|
| 92 |
rand_max = RAND_CHARS.bytesize
|
|
| 93 | 93 |
ret = "" |
| 94 | 94 |
len.times{ ret << RAND_CHARS[rand(rand_max)] }
|
| 95 | 95 |
ret |