Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frozen string literal support #465

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/download.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end
buf_size = 1024 * 16
STDOUT.sync = true
File.open(File.expand_path('10M.bin', File.dirname(__FILE__))) do |file|
buf = ''
buf = ''.dup
while !file.read(buf_size, buf).nil?
print dump_chunk(buf)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/hexdump.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: binary
# frozen_string_literal: true

# This was written by Arai-san and published at
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/31987
Expand All @@ -11,7 +12,7 @@ def encode(str)
result = []
while raw = str.slice(offset, 16) and raw.length > 0
# data field
data = ''
data = ''.dup
for v in raw.unpack('N* a*')
if v.kind_of? Integer
data << sprintf("%08x ", v)
Expand Down
2 changes: 2 additions & 0 deletions lib/http-access2.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPAccess2 - HTTP accessing library.
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <[email protected]>.

Expand Down
1 change: 1 addition & 0 deletions lib/http-access2/cookie.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# frozen_string_literal: true
require 'httpclient/cookie'
1 change: 1 addition & 0 deletions lib/http-access2/http.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# frozen_string_literal: true
require 'httpclient/http'
6 changes: 4 additions & 2 deletions lib/httpclient.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down Expand Up @@ -949,7 +951,7 @@ def request_async(method, uri, query = nil, body = nil, header = {})
def request_async2(method, uri, *args)
query, body, header = keyword_argument(args, :query, :body, :header)
if [:post, :put].include?(method)
body ||= ''
body ||= ''.dump
end
if method == :propfind
header ||= PROPFIND_DEFAULT_EXTHEADER
Expand Down Expand Up @@ -1240,7 +1242,7 @@ def do_get_block(req, proxy, conn, &block)
conn.push(res)
return res
end
content = block ? nil : ''
content = block ? nil : ''.dup
res = HTTP::Message.new_response(content, req.header)
@debug_dev << "= Request\n\n" if @debug_dev
sess = @session_manager.query(req, proxy)
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/auth.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/cookie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# do not override if httpclient/webagent-cookie is loaded already
unless defined?(HTTPClient::CookieManager)
begin # for catching LoadError and load webagent-cookie instead
Expand Down
13 changes: 7 additions & 6 deletions lib/httpclient/http.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
Expand Down Expand Up @@ -238,7 +239,7 @@ def content_type=(content_type)
if defined?(Encoding::ASCII_8BIT)
def set_body_encoding
if type = self.content_type
OpenURI::Meta.init(o = '')
OpenURI::Meta.init(o = ''.dup)
o.meta_add_field('content-type', type)
@body_encoding = o.encoding
end
Expand Down Expand Up @@ -491,7 +492,7 @@ def init_response(body = nil)
# String.
#
# assert: @size is not nil
def dump(header = '', dev = '')
def dump(header = ''.dup, dev = ''.dup)
if @body.is_a?(Parts)
dev << header
@body.parts.each do |part|
Expand Down Expand Up @@ -521,7 +522,7 @@ def dump(header = '', dev = '')
# reason. (header is dumped to dev, too)
# If no dev (the second argument) given, this method returns a dumped
# String.
def dump_chunked(header = '', dev = '')
def dump_chunked(header = ''.dup, dev = ''.dup)
dev << header
if @body.is_a?(Parts)
@body.parts.each do |part|
Expand Down Expand Up @@ -574,7 +575,7 @@ def reset_pos(io)
end

def dump_file(io, dev, sz)
buf = ''
buf = ''.dup
rest = sz
while rest > 0
n = io.read([rest, @chunk_size].min, buf)
Expand All @@ -585,7 +586,7 @@ def dump_file(io, dev, sz)
end

def dump_chunks(io, dev)
buf = ''
buf = ''.dup
while !io.read(@chunk_size, buf).nil?
dev << dump_chunk(buf)
end
Expand Down Expand Up @@ -954,7 +955,7 @@ def initialize # :nodoc:

# Dumps message (header and body) to given dev.
# dev needs to respond to <<.
def dump(dev = '')
def dump(dev = ''.dup)
str = @http_header.dump + CRLF
if @http_header.chunked
dev = @http_body.dump_chunked(str, dev)
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/include_client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# It is useful to re-use a HTTPClient instance for multiple requests, to
# re-use HTTP 1.1 persistent connections.
#
Expand Down
6 changes: 4 additions & 2 deletions lib/httpclient/jruby_ssl_socket.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down Expand Up @@ -42,7 +44,7 @@ def initialize(socket, debug_dev = nil)
@outstr = @socket.getOutputStream
@instr = BufferedInputStream.new(@socket.getInputStream)
@buf = (' ' * BUF_SIZE).to_java_bytes
@bufstr = ''
@bufstr = ''.dup
end

def close
Expand Down Expand Up @@ -346,7 +348,7 @@ def add(cert_source)
File.read(cert_source).each_line do |line|
case line
when /-----BEGIN CERTIFICATE-----/
pem = ''
pem = ''.dup
when /-----END CERTIFICATE-----/
load_pem(pem)
# keep parsing in case where multiple certificates in a file
Expand Down
4 changes: 3 additions & 1 deletion lib/httpclient/session.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down Expand Up @@ -950,7 +952,7 @@ def read_body_rest
end

def empty_bin_str
str = ''
str = ''.dup
str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
str
end
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/ssl_config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/ssl_socket.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/timeout.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down
4 changes: 3 additions & 1 deletion lib/httpclient/util.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down Expand Up @@ -64,7 +66,7 @@ class AddressableURI < Addressable::URI
# Overwrites the original definition just for one line...
def authority
self.host && @authority ||= (begin
authority = ""
authority = "".dup
if self.userinfo != nil
authority << "#{self.userinfo}@"
end
Expand Down
2 changes: 2 additions & 0 deletions lib/httpclient/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class HTTPClient
VERSION = '2.8.3'
end
2 changes: 2 additions & 0 deletions lib/httpclient/webagent-cookie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# cookie.rb is redistributed file which is originally included in Webagent
# version 0.6.2 by TAKAHASHI `Maki' Masayoshi. And it contains some bug fixes.
# You can download the entire package of Webagent from
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonclient.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'httpclient'
require 'json'

Expand Down
2 changes: 2 additions & 0 deletions lib/oauthclient.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# HTTPClient - HTTP client library.
# Copyright (C) 2000-2015 NAKAMURA, Hiroshi <[email protected]>.
#
Expand Down
2 changes: 2 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

begin
require 'simplecov'
require 'simplecov-rcov'
Expand Down
1 change: 1 addition & 0 deletions test/jruby_ssl_socket/test_pemutils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require File.expand_path('helper', File.join(File.dirname(__FILE__), ".."))


Expand Down
1 change: 1 addition & 0 deletions test/runner.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# frozen_string_literal: true
require 'test/unit'
exit Test::Unit::AutoRunner.run(true, File.dirname($0))
1 change: 1 addition & 0 deletions test/sslsvr.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'webrick/https'
require 'logger'
require 'rbconfig'
Expand Down
31 changes: 16 additions & 15 deletions test/test_auth.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require File.expand_path('helper', File.dirname(__FILE__))
require 'digest/md5'
require 'rack'
Expand Down Expand Up @@ -176,7 +177,7 @@ def test_BASIC_auth_force
c.www_auth.basic_auth.instance_eval { @scheme = "BASIC" }
#
c.force_basic_auth = true
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth"))
assert_equal('Authorization: Basic YWRtaW46YWRtaW4='.upcase, str.split(/\r?\n/)[5].upcase)
Expand Down Expand Up @@ -249,7 +250,7 @@ def test_basic_auth_reuses_credentials
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth/"))
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content("http://localhost:#{serverport}/basic_auth/sub/dir/")
assert_match(/Authorization: Basic YWRtaW46YWRtaW4=/, str)
end
Expand All @@ -265,7 +266,7 @@ def test_digest_auth_reuses_credentials
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
assert_equal('digest_auth OK', c.get_content("http://localhost:#{serverport}/digest_auth/"))
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content("http://localhost:#{serverport}/digest_auth/sub/dir/")
assert_match(/Authorization: Digest/, str)
end
Expand Down Expand Up @@ -311,7 +312,7 @@ def test_perfer_digest
c.set_auth('http://example.com/', 'admin', 'admin')
c.test_loopback_http_response << "HTTP/1.0 401 Unauthorized\nWWW-Authenticate: Basic realm=\"foo\"\nWWW-Authenticate: Digest realm=\"foo\", nonce=\"nonce\", stale=false\nContent-Length: 2\n\nNG"
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://example.com/')
assert_match(/^Authorization: Digest/, str)
end
Expand All @@ -327,7 +328,7 @@ def test_proxy_auth
c.set_proxy_auth('admin', 'admin')
c.test_loopback_http_response << "HTTP/1.0 407 Unauthorized\nProxy-Authenticate: Basic realm=\"foo\"\nContent-Length: 2\n\nNG"
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://example.com/')
assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
end
Expand All @@ -337,7 +338,7 @@ def test_proxy_auth_force
c.set_proxy_auth('admin', 'admin')
c.force_basic_auth = true
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://example.com/')
assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
end
Expand All @@ -349,7 +350,7 @@ def test_proxy_auth_reuses_credentials
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.get_content('http://www1.example.com/')
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://www2.example.com/')
assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
end
Expand All @@ -363,7 +364,7 @@ def test_digest_proxy_auth_loop
ha1 = md5.hexdigest("admin:foo:admin")
ha2 = md5.hexdigest("GET:/")
response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://example.com/')
assert_match(/Proxy-Authorization: Digest/, str)
assert_match(%r"response=\"#{response}\"", str)
Expand Down Expand Up @@ -394,7 +395,7 @@ def test_prefer_digest_to_basic_proxy_auth
ha1 = md5.hexdigest("admin:foo:admin")
ha2 = md5.hexdigest("GET:/")
response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://example.com/')
assert_match(/Proxy-Authorization: Digest/, str)
assert_match(%r"response=\"#{response}\"", str)
Expand All @@ -411,7 +412,7 @@ def test_digest_proxy_auth_reuses_credentials
ha2 = md5.hexdigest("GET:/")
response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
c.get_content('http://www1.example.com/')
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://www2.example.com/')
assert_match(/Proxy-Authorization: Digest/, str)
assert_match(%r"response=\"#{response}\"", str)
Expand All @@ -433,19 +434,19 @@ def test_oauth
c.www_auth.oauth.set_config('http://photos.example.net/', config)
c.www_auth.oauth.challenge('http://photos.example.net/')
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
#
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get_content('http://photos.example.net/photos?file=vacation.jpg&size=original')
assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
#
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.post_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
assert(str.index(%q(POST /photos)))
assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="wPkvxykrw%2BBTdCcGqKr%2B3I%2BPsiM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
Expand Down Expand Up @@ -475,7 +476,7 @@ def test_negotiate_and_basic
c.test_loopback_http_response << %Q(HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABAAAAAAAAAAAAAAA=\r\nConnection: Keep-Alive\r\nContent-Length: 0\r\n\r\n)
c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\na)
c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\nb)
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.set_auth('http://www.example.org/', 'admin', 'admin')
# Do NTLM negotiation
c.get('http://www.example.org/foo')
Expand All @@ -484,7 +485,7 @@ def test_negotiate_and_basic
assert_match(%r(Authorization: NTLM), str)
assert_not_match(%r(Authorization: Basic), str)
# ditto for other resource that is protected with NTLM
c.debug_dev = str = ''
c.debug_dev = str = ''.dup
c.get('http://www.example.org/foo/subdir')
assert_not_match(%r(Authorization: NTLM), str)
assert_not_match(%r(Authorization: Basic), str)
Expand Down
Loading