ruby-changes:53767
From: mame <ko1@a...>
Date: Mon, 26 Nov 2018 14:29:49 +0900 (JST)
Subject: [ruby-changes:53767] mame:r65984 (trunk): lib/webrick: explicitly convert header values to a string
mame 2018-11-26 14:29:45 +0900 (Mon, 26 Nov 2018) New Revision: 65984 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65984 Log: lib/webrick: explicitly convert header values to a string The values of @header are expected to be all strings; WEBrick::HTTPResponse::[]=(key, val) explicitly converts the second argument to a string and assigns it to @header hash. However, there were some points in WEBrick internal code that assigns non-String to @header. This change fixes the issues. The values are checked by `header_value =~ /\r\n/` in check_header. The type confusion caused conflict with removal of `Object#=~` [Feature #15231]. Modified files: trunk/lib/webrick/httpresponse.rb trunk/lib/webrick/httpservlet/filehandler.rb Index: lib/webrick/httpresponse.rb =================================================================== --- lib/webrick/httpresponse.rb (revision 65983) +++ lib/webrick/httpresponse.rb (revision 65984) @@ -254,7 +254,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpresponse.rb#L254 @header.delete('content-length') elsif @header['content-length'].nil? unless @body.is_a?(IO) - @header['content-length'] = @body ? @body.bytesize : 0 + @header['content-length'] = (@body ? @body.bytesize : 0).to_s end end @@ -277,7 +277,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpresponse.rb#L277 # Location is a single absoluteURI. if location = @header['location'] if @request_uri - @header['location'] = @request_uri.merge(location) + @header['location'] = @request_uri.merge(location).to_s end end end Index: lib/webrick/httpservlet/filehandler.rb =================================================================== --- lib/webrick/httpservlet/filehandler.rb (revision 65983) +++ lib/webrick/httpservlet/filehandler.rb (revision 65984) @@ -55,7 +55,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L55 else mtype = HTTPUtils::mime_type(@local_path, @config[:MimeTypes]) res['content-type'] = mtype - res['content-length'] = st.size + res['content-length'] = st.size.to_s res['last-modified'] = mtime.httpdate res.body = File.open(@local_path, "rb") end @@ -144,7 +144,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L144 raise HTTPStatus::RequestRangeNotSatisfiable if first < 0 res['content-type'] = mtype res['content-range'] = "bytes #{first}-#{last}/#{filesize}" - res['content-length'] = last - first + 1 + res['content-length'] = (last - first + 1).to_s res.body = io.dup else raise HTTPStatus::BadRequest -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/