Skip to content

Commit 556747d

Browse files
Support running with --enable=frozen-string-literal
In apps that run with --enable=frozen-string-literal we can get a FrozenError. Using String.new instead of '' fixes that without breaking it for anyone else. When running the specs with frozen strings (RUBYOPT="--enable=frozen-string-literal" rake), there were three files that generate errors. I added the magic comment: # frozen-string-literal: false to those to work both ways. I have a related PR on http-2 to get all the specs passing: igrigorik/http-2#161
1 parent 87c96dd commit 556747d

5 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/net-http2/socket.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def self.proxy_tcp_socket(uri, options)
7070
# So we’ll keep HTTP/1.1
7171
http_version = '1.1'
7272

73-
buf = "CONNECT #{uri.host}:#{uri.port} HTTP/#{http_version}\r\n"
73+
buf = String.new
74+
buf << "CONNECT #{uri.host}:#{uri.port} HTTP/#{http_version}\r\n"
7475
buf << "Host: #{uri.host}:#{uri.port}\r\n"
7576
if proxy_user
7677
credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
@@ -87,7 +88,7 @@ def self.proxy_tcp_socket(uri, options)
8788
private
8889

8990
def self.validate_proxy_response!(socket)
90-
result = ''
91+
result = String.new
9192
loop do
9293
line = socket.gets
9394
break if !line || line.strip.empty?

lib/net-http2/stream.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Stream
55
def initialize(options={})
66
@h2_stream = options[:h2_stream]
77
@headers = {}
8-
@data = ''
8+
@data = String.new
99
@request = nil
1010
@async = false
1111
@completed = false

spec/api/errors_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen-string-literal: false
12
require 'spec_helper'
23

34
describe "Errors" do

spec/api/sending_async_requests_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen-string-literal: false
12
require 'spec_helper'
23

34
describe "Sending async requests" do

spec/support/dummy_server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen-string-literal: false
12
module NetHttp2
23

34
module Dummy

0 commit comments

Comments
 (0)