aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-10-26 20:30:04 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-10-26 20:30:04 +0900
commitff7e81f4aba4995633b91adf0bbb8e45a6357444 (patch)
treee9101df02c26d52c60597d325e6aae6da0211651
parent1f541f2a210c32fbb094d3948347940cb107e478 (diff)
parent462b3646c9026e36d84d5c03caa7b63345d64f9f (diff)
downloadplum-ff7e81f4aba4995633b91adf0bbb8e45a6357444.tar.gz
Merge branch 'frozen-string-literal'
-rw-r--r--Guardfile1
-rw-r--r--Rakefile1
-rw-r--r--examples/non_tls_server.rb28
-rw-r--r--examples/static_server.rb13
-rw-r--r--lib/plum/binary_string.rb1
-rw-r--r--lib/plum/connection.rb5
-rw-r--r--lib/plum/connection_utils.rb1
-rw-r--r--lib/plum/errors.rb1
-rw-r--r--lib/plum/event_emitter.rb1
-rw-r--r--lib/plum/flow_control.rb3
-rw-r--r--lib/plum/frame.rb1
-rw-r--r--lib/plum/frame_factory.rb15
-rw-r--r--lib/plum/frame_utils.rb1
-rw-r--r--lib/plum/hpack/constants.rb1
-rw-r--r--lib/plum/hpack/context.rb1
-rw-r--r--lib/plum/hpack/decoder.rb1
-rw-r--r--lib/plum/hpack/encoder.rb11
-rw-r--r--lib/plum/hpack/huffman.rb7
-rw-r--r--lib/plum/http_connection.rb14
-rw-r--r--lib/plum/https_connection.rb1
-rw-r--r--lib/plum/rack/cli.rb1
-rw-r--r--lib/plum/rack/config.rb1
-rw-r--r--lib/plum/rack/connection.rb7
-rw-r--r--lib/plum/rack/dsl.rb1
-rw-r--r--lib/plum/rack/listener.rb3
-rw-r--r--lib/plum/rack/server.rb1
-rw-r--r--lib/plum/stream.rb1
-rw-r--r--lib/plum/stream_utils.rb1
-rw-r--r--lib/plum/version.rb1
-rw-r--r--lib/rack/handler/plum.rb1
-rw-r--r--plum.gemspec1
31 files changed, 76 insertions, 51 deletions
diff --git a/Guardfile b/Guardfile
index 88db78f..e9cb220 100644
--- a/Guardfile
+++ b/Guardfile
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
guard :minitest, env: { "SKIP_COVERAGE" => true } do
# with Minitest::Unit
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
diff --git a/Rakefile b/Rakefile
index 677cebd..3c31423 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
require "bundler/gem_tasks"
require "rake/testtask"
require "yard"
diff --git a/examples/non_tls_server.rb b/examples/non_tls_server.rb
index 54e4f19..2df12bb 100644
--- a/examples/non_tls_server.rb
+++ b/examples/non_tls_server.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
require "plum"
require "socket"
@@ -53,7 +54,7 @@ loop do
stream.on(:open) do
headers = nil
- data = ""
+ data = String.new
end
stream.on(:headers) do |headers_|
@@ -69,8 +70,8 @@ loop do
stream.on(:end_stream) do
case [headers[":method"], headers[":path"]]
when ["GET", "/"]
- body = "Hello World! <a href=/abc.html>ABC</a> <a href=/fgsd>Not found</a>"
- body << <<-EOF
+ body = <<-EOF
+ Hello World! <a href=/abc.html>ABC</a> <a href=/fgsd>Not found</a>
<form action=post.page method=post>
<input type=text name=key value=default_value>
<input type=submit>
@@ -80,7 +81,7 @@ loop do
":status": "200",
"server": "plum",
"content-type": "text/html",
- "content-length": body.size
+ "content-length": body.bytesize
}, body)
when ["POST", "/post.page"]
body = "Posted value is: #{CGI.unescape(data).gsub("<", "&lt;").gsub(">", "&gt;")}<br> <a href=/>Back to top page</a>"
@@ -88,7 +89,7 @@ loop do
":status": "200",
"server": "plum",
"content-type": "text/html",
- "content-length": body.size
+ "content-length": body.bytesize
}, body)
else
body = "Page not found! <a href=/>Back to top page</a>"
@@ -96,7 +97,7 @@ loop do
":status": "404",
"server": "plum",
"content-type": "text/html",
- "content-length": body.size
+ "content-length": body.bytesize
}, body)
end
end
@@ -106,15 +107,12 @@ loop do
begin
plum.run
rescue Plum::LegacyHTTPError
- data = "Use modern web browser with HTTP/2 support."
-
- resp = ""
- resp << "HTTP/1.1 505 HTTP Version Not Supported\r\n"
- resp << "Content-Type: text/plain\r\n"
- resp << "Content-Length: #{data.bytesize}\r\n"
- resp << "Server: plum/#{Plum::VERSION}\r\n"
- resp << "\r\n"
- resp << data
+ resp = "HTTP/1.1 505 HTTP Version Not Supported\r\n"
+ "Content-Type: text/plain\r\n"
+ "Content-Length: #{data.bytesize}\r\n"
+ "Server: plum/#{Plum::VERSION}\r\n"
+ "\r\n"
+ "Use modern web browser with HTTP/2 support."
sock.write(resp)
rescue
diff --git a/examples/static_server.rb b/examples/static_server.rb
index 4e47f41..b065d83 100644
--- a/examples/static_server.rb
+++ b/examples/static_server.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
require "plum"
require "openssl"
@@ -71,7 +72,7 @@ loop do
stream.on(:open) do
headers = nil
- data = ""
+ data = String.new
end
stream.on(:headers) do |headers_|
@@ -87,8 +88,8 @@ loop do
stream.on(:end_stream) do
case [headers[":method"], headers[":path"]]
when ["GET", "/"]
- body = "Hello World! <a href=/abc.html>ABC</a> <a href=/fgsd>Not found</a>"
- body << <<-EOF
+ body = <<-EOF
+ Hello World! <a href=/abc.html>ABC</a> <a href=/fgsd>Not found</a>
<form action=post.page method=post>
<input type=text name=key value=default_value>
<input type=submit>
@@ -114,9 +115,9 @@ loop do
"content-type": "text/html",
"content-length": body.size
}, body)
- image = ("iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAAACVBMVEX///93o0jG/4mTMy20AAAA" <<
- "bklEQVQ4y2NgoAoIRQJkCoSimIdTgJGBBU1ABE1A1AVdBQuaACu6gCALhhZ0axlZCDgMWYAB6ilU" <<
- "35IoADEMxWyyBDD45AhQCFahM0kXWIVu3sAJrILzyBcgytoFeATABBcXWohhCEC14BCgGAAAX1ZQ" <<
+ image = ("iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAAACVBMVEX///93o0jG/4mTMy20AAAA"
+ "bklEQVQ4y2NgoAoIRQJkCoSimIdTgJGBBU1ABE1A1AVdBQuaACu6gCALhhZ0axlZCDgMWYAB6ilU"
+ "35IoADEMxWyyBDD45AhQCFahM0kXWIVu3sAJrILzyBcgytoFeATABBcXWohhCEC14BCgGAAAX1ZQ"
"ZtJp0zAAAAAASUVORK5CYII=").unpack("m")[0]
i_stream.respond({
":status": "200",
diff --git a/lib/plum/binary_string.rb b/lib/plum/binary_string.rb
index 8c98693..400c57b 100644
--- a/lib/plum/binary_string.rb
+++ b/lib/plum/binary_string.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module BinaryString
refine String do
diff --git a/lib/plum/connection.rb b/lib/plum/connection.rb
index a69a9c8..a8b2916 100644
--- a/lib/plum/connection.rb
+++ b/lib/plum/connection.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -6,7 +7,7 @@ module Plum
include FlowControl
include ConnectionUtils
- CLIENT_CONNECTION_PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".freeze
+ CLIENT_CONNECTION_PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
DEFAULT_SETTINGS = {
header_table_size: 4096, # octets
@@ -25,7 +26,7 @@ module Plum
@writer = writer
@local_settings = Hash.new {|hash, key| DEFAULT_SETTINGS[key] }.merge!(local_settings)
@remote_settings = Hash.new {|hash, key| DEFAULT_SETTINGS[key] }
- @buffer = "".force_encoding(Encoding::BINARY)
+ @buffer = String.new
@streams = {}
@state = :negotiation
@hpack_decoder = HPACK::Decoder.new(@local_settings[:header_table_size])
diff --git a/lib/plum/connection_utils.rb b/lib/plum/connection_utils.rb
index 8ab90e1..8c96267 100644
--- a/lib/plum/connection_utils.rb
+++ b/lib/plum/connection_utils.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
diff --git a/lib/plum/errors.rb b/lib/plum/errors.rb
index 44b711f..9df4668 100644
--- a/lib/plum/errors.rb
+++ b/lib/plum/errors.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
class Error < StandardError; end
class HPACKError < Error; end
diff --git a/lib/plum/event_emitter.rb b/lib/plum/event_emitter.rb
index 572900e..7bc9695 100644
--- a/lib/plum/event_emitter.rb
+++ b/lib/plum/event_emitter.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module EventEmitter
# Registers an event handler to specified event. An event can have multiple handlers.
diff --git a/lib/plum/flow_control.rb b/lib/plum/flow_control.rb
index 2a93341..cfb181d 100644
--- a/lib/plum/flow_control.rb
+++ b/lib/plum/flow_control.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -27,7 +28,7 @@ module Plum
# @param wsi [Integer] The amount to increase receiving window size. The legal range is 1 to 2^32-1.
def window_update(wsi)
@recv_remaining_window += wsi
- payload = "".push_uint32(wsi)
+ payload = String.new.push_uint32(wsi)
sid = (Stream === self) ? self.id : 0
send_immediately Frame.new(type: :window_update, stream_id: sid, payload: payload)
end
diff --git a/lib/plum/frame.rb b/lib/plum/frame.rb
index 981bf55..fdd16ef 100644
--- a/lib/plum/frame.rb
+++ b/lib/plum/frame.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
diff --git a/lib/plum/frame_factory.rb b/lib/plum/frame_factory.rb
index 686f88e..51908ec 100644
--- a/lib/plum/frame_factory.rb
+++ b/lib/plum/frame_factory.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -6,7 +7,7 @@ module Plum
# @param stream_id [Integer] The stream ID.
# @param error_type [Symbol] The error type defined in RFC 7540 Section 7.
def rst_stream(stream_id, error_type)
- payload = "".push_uint32(HTTPError::ERROR_CODES[error_type])
+ payload = String.new.push_uint32(HTTPError::ERROR_CODES[error_type])
Frame.new(type: :rst_stream, stream_id: stream_id, payload: payload)
end
@@ -16,9 +17,9 @@ module Plum
# @param message [String] Additional debug data.
# @see RFC 7540 Section 6.8
def goaway(last_id, error_type, message = "")
- payload = "".push_uint32((last_id || 0) | (0 << 31))
- .push_uint32(HTTPError::ERROR_CODES[error_type])
- .push(message)
+ payload = String.new.push_uint32((last_id || 0) | (0 << 31))
+ .push_uint32(HTTPError::ERROR_CODES[error_type])
+ .push(message)
Frame.new(type: :goaway, stream_id: 0, payload: payload)
end
@@ -26,7 +27,7 @@ module Plum
# @param ack [Symbol] Pass :ack to create an ACK frame.
# @param args [Hash<Symbol, Integer>] The settings values to send.
def settings(ack = nil, **args)
- payload = args.inject("") {|payload, (key, value)|
+ payload = args.inject(String.new) {|payload, (key, value)|
id = Frame::SETTINGS_TYPE[key] or raise ArgumentError.new("invalid settings type")
payload.push_uint16(id)
payload.push_uint32(value)
@@ -71,8 +72,8 @@ module Plum
# @param encoded [String] Request headers.
# @param flags [Array<Symbol>] Flags.
def push_promise(stream_id, new_id, encoded, *flags)
- payload = "".push_uint32(0 << 31 | new_id)
- .push(encoded)
+ payload = String.new.push_uint32(new_id)
+ .push(encoded)
Frame.new(type: :push_promise, stream_id: stream_id, flags: flags, payload: payload)
end
diff --git a/lib/plum/frame_utils.rb b/lib/plum/frame_utils.rb
index e52d444..20c79de 100644
--- a/lib/plum/frame_utils.rb
+++ b/lib/plum/frame_utils.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
diff --git a/lib/plum/hpack/constants.rb b/lib/plum/hpack/constants.rb
index 0fe4caa..4eac05c 100644
--- a/lib/plum/hpack/constants.rb
+++ b/lib/plum/hpack/constants.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module HPACK
# RFC7541 Appendix A
diff --git a/lib/plum/hpack/context.rb b/lib/plum/hpack/context.rb
index e51b56f..622fe36 100644
--- a/lib/plum/hpack/context.rb
+++ b/lib/plum/hpack/context.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module HPACK
module Context
diff --git a/lib/plum/hpack/decoder.rb b/lib/plum/hpack/decoder.rb
index 2efa865..48546f8 100644
--- a/lib/plum/hpack/decoder.rb
+++ b/lib/plum/hpack/decoder.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
diff --git a/lib/plum/hpack/encoder.rb b/lib/plum/hpack/encoder.rb
index 152b0fe..d817589 100644
--- a/lib/plum/hpack/encoder.rb
+++ b/lib/plum/hpack/encoder.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -10,9 +11,8 @@ module Plum
@indexing = indexing
@huffman = huffman
end
-
def encode(headers)
- out = ""
+ out = String.new.force_encoding(Encoding::BINARY)
headers.each do |name, value|
name = name.to_s
value = value.to_s
@@ -24,7 +24,7 @@ module Plum
out << encode_literal(name, value)
end
end
- out.force_encoding(Encoding::BINARY)
+ out
end
private
@@ -46,7 +46,7 @@ module Plum
else
fb = "\x00"
end
- fb.force_encoding(Encoding::BINARY) << encode_string(name) << encode_string(value)
+ (fb + encode_string(name)) << encode_string(value)
end
# +---+---+---+---+---+---+---+---+
@@ -106,8 +106,7 @@ module Plum
def encode_string_huffman(str)
huffman_str = Huffman.encode(str)
- lenstr = encode_integer(huffman_str.bytesize, 7, 0b10000000)
- lenstr << huffman_str
+ encode_integer(huffman_str.bytesize, 7, 0b10000000) << huffman_str
end
end
end
diff --git a/lib/plum/hpack/huffman.rb b/lib/plum/hpack/huffman.rb
index 40fae59..e34e1af 100644
--- a/lib/plum/hpack/huffman.rb
+++ b/lib/plum/hpack/huffman.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -7,7 +8,7 @@ module Plum
# Static-Huffman-encodes the specified String.
def encode(bytestr)
- out = ""
+ out = String.new
bytestr.each_byte do |b|
out << HUFFMAN_TABLE[b]
end
@@ -19,13 +20,13 @@ module Plum
def decode(encoded)
bits = encoded.unpack("B*")[0]
out = []
- buf = ""
+ buf = String.new
bits.each_char do |cb|
buf << cb
if c = HUFFMAN_TABLE_INVERSED[buf]
raise HPACKError.new("huffman: EOS detected") if c == 256
out << c
- buf = ""
+ buf.clear
end
end
diff --git a/lib/plum/http_connection.rb b/lib/plum/http_connection.rb
index 9af246d..1c30e6e 100644
--- a/lib/plum/http_connection.rb
+++ b/lib/plum/http_connection.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -7,7 +8,7 @@ module Plum
def initialize(sock, local_settings = {})
require "http/parser"
@_headers = nil
- @_body = ""
+ @_body = String.new
@_http_parser = setup_parser
@sock = sock
super(@sock.method(:write), local_settings)
@@ -65,12 +66,11 @@ module Plum
process_first_request
}
- resp = ""
- resp << "HTTP/1.1 101 Switching Protocols\r\n"
- resp << "Connection: Upgrade\r\n"
- resp << "Upgrade: h2c\r\n"
- resp << "Server: plum/#{Plum::VERSION}\r\n"
- resp << "\r\n"
+ resp = "HTTP/1.1 101 Switching Protocols\r\n"
+ "Connection: Upgrade\r\n"
+ "Upgrade: h2c\r\n"
+ "Server: plum/#{Plum::VERSION}\r\n"
+ "\r\n"
@sock.write(resp)
end
diff --git a/lib/plum/https_connection.rb b/lib/plum/https_connection.rb
index d7d1819..c719c2e 100644
--- a/lib/plum/https_connection.rb
+++ b/lib/plum/https_connection.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
class HTTPSConnection < Connection
attr_reader :sock
diff --git a/lib/plum/rack/cli.rb b/lib/plum/rack/cli.rb
index bc5a767..18fe90f 100644
--- a/lib/plum/rack/cli.rb
+++ b/lib/plum/rack/cli.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
require "optparse"
require "rack/builder"
diff --git a/lib/plum/rack/config.rb b/lib/plum/rack/config.rb
index 0ab04c5..b75fd08 100644
--- a/lib/plum/rack/config.rb
+++ b/lib/plum/rack/config.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module Rack
class Config
diff --git a/lib/plum/rack/connection.rb b/lib/plum/rack/connection.rb
index cf8e52e..0c53e3d 100644
--- a/lib/plum/rack/connection.rb
+++ b/lib/plum/rack/connection.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
@@ -35,7 +36,7 @@ module Plum
reqs = {}
@plum.on(:headers) { |stream, h|
- reqs[stream] = { headers: h, data: "".force_encoding(Encoding::BINARY) }
+ reqs[stream] = { headers: h, data: String.new.force_encoding(Encoding::BINARY) }
}
@plum.on(:data) { |stream, d|
@@ -140,12 +141,12 @@ module Plum
else
if "cookie" == k && ebase["HTTP_COOKIE"]
if ebase["HTTP_COOKIE"].frozen?
- ebase["HTTP_COOKIE"] += "; " << v
+ (ebase["HTTP_COOKIE"] += "; ") << v
else
ebase["HTTP_COOKIE"] << "; " << v
end
else
- ebase["HTTP_" << k.tr("-", "_").upcase!] = v
+ ebase["HTTP_" + k.tr("-", "_").upcase!] = v
end
end
end
diff --git a/lib/plum/rack/dsl.rb b/lib/plum/rack/dsl.rb
index f4ee850..eb2ba17 100644
--- a/lib/plum/rack/dsl.rb
+++ b/lib/plum/rack/dsl.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module Rack
module DSL
diff --git a/lib/plum/rack/listener.rb b/lib/plum/rack/listener.rb
index 02e00a1..31bbc8c 100644
--- a/lib/plum/rack/listener.rb
+++ b/lib/plum/rack/listener.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module Rack
class BaseListener
@@ -76,7 +77,7 @@ module Plum
ef.subject_certificate = cert
ef.issuer_certificate = cert
cert.extensions = [
- ef.create_extension("basicConstraints","CA:TRUE", true),
+ ef.create_extension("basicConstraints", "CA:TRUE", true),
ef.create_extension("subjectKeyIdentifier", "hash"),
]
cert.add_extension ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
diff --git a/lib/plum/rack/server.rb b/lib/plum/rack/server.rb
index 608bf18..0f8338c 100644
--- a/lib/plum/rack/server.rb
+++ b/lib/plum/rack/server.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
module Rack
class Server
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb
index 45bd613..e67d80e 100644
--- a/lib/plum/stream.rb
+++ b/lib/plum/stream.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
diff --git a/lib/plum/stream_utils.rb b/lib/plum/stream_utils.rb
index eede307..a8d959f 100644
--- a/lib/plum/stream_utils.rb
+++ b/lib/plum/stream_utils.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
diff --git a/lib/plum/version.rb b/lib/plum/version.rb
index 45118e1..2b37004 100644
--- a/lib/plum/version.rb
+++ b/lib/plum/version.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Plum
VERSION = "0.1.2"
end
diff --git a/lib/rack/handler/plum.rb b/lib/rack/handler/plum.rb
index 30eed72..cf34ee4 100644
--- a/lib/rack/handler/plum.rb
+++ b/lib/rack/handler/plum.rb
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
module Rack
module Handler
class Plum
diff --git a/plum.gemspec b/plum.gemspec
index 2e3ff5d..cb1a3b6 100644
--- a/plum.gemspec
+++ b/plum.gemspec
@@ -1,3 +1,4 @@
+# -*- frozen-string-literal: true -*-
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "plum/version"