aboutsummaryrefslogtreecommitdiffstats
path: root/examples
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 /examples
parent1f541f2a210c32fbb094d3948347940cb107e478 (diff)
parent462b3646c9026e36d84d5c03caa7b63345d64f9f (diff)
downloadplum-ff7e81f4aba4995633b91adf0bbb8e45a6357444.tar.gz
Merge branch 'frozen-string-literal'
Diffstat (limited to 'examples')
-rw-r--r--examples/non_tls_server.rb28
-rw-r--r--examples/static_server.rb13
2 files changed, 20 insertions, 21 deletions
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",