Skip to content

Commit 83ac7ff

Browse files
committed
Modernize gem.
1 parent dc67087 commit 83ac7ff

29 files changed

+247
-245
lines changed

config/sus.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2022, by Samuel Williams.
4+
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'covered/sus'
6+
require "covered/sus"
77
include Covered::Sus

examples/puma/config.ru

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
require 'protocol/http/middleware'
2-
require_relative '../../lib/protocol/rack'
1+
# frozen_string_literal: true
2+
3+
require "protocol/http/middleware"
4+
require_relative "../../lib/protocol/rack"
35

46
# Your native application:
57
middleware = Protocol::HTTP::Middleware::HelloWorld
68

79
run proc{|env|
8-
# Convert the rack request to a compatible rich request object:
9-
request = Protocol::Rack::Request[env]
10-
11-
# Call your application
12-
response = middleware.call(request)
13-
14-
Protocol::Rack::Adapter.make_response(env, response)
10+
# Convert the rack request to a compatible rich request object:
11+
request = Protocol::Rack::Request[env]
12+
13+
# Call your application
14+
response = middleware.call(request)
15+
16+
Protocol::Rack::Adapter.make_response(env, response)
1517
}

examples/server/server.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2022, by Samuel Williams.
5+
# Copyright, 2022-2024, by Samuel Williams.
66

7-
require 'async'
8-
require 'async/http/server'
9-
require 'async/http/client'
10-
require 'async/http/endpoint'
11-
require_relative '../../lib/protocol/rack/adapter'
7+
require "async"
8+
require "async/http/server"
9+
require "async/http/client"
10+
require "async/http/endpoint"
11+
require_relative "../../lib/protocol/rack/adapter"
1212

1313
app = proc{|env| [200, {}, ["Hello World"]]}
1414
middleware = Protocol::Rack::Adapter.new(app)
1515

1616
Async do
17-
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
18-
19-
server_task = Async(transient: true) do
20-
server = Async::HTTP::Server.new(middleware, endpoint)
21-
server.run
22-
end
23-
24-
client = Async::HTTP::Client.new(endpoint)
25-
pp client.get("/").read
17+
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
18+
19+
server_task = Async(transient: true) do
20+
server = Async::HTTP::Server.new(middleware, endpoint)
21+
server.run
22+
end
23+
24+
client = Async::HTTP::Client.new(endpoint)
25+
pp client.get("/").read
2626
end

fixtures/server_context.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2022, by Samuel Williams.
4+
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'sus/fixtures/async/http/server_context'
6+
require "sus/fixtures/async/http/server_context"
77

88
module ServerContext
99
include Sus::Fixtures::Async::HTTP::ServerContext
1010

1111
def app
12-
->(env){[200, {}, ['Hello World!']]}
12+
->(env){[200, {}, ["Hello World!"]]}
1313
end
1414

1515
def middleware

gems.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
gemspec
99

1010
group :maintenance, optional: true do
11-
gem 'bake-modernize'
12-
gem 'bake-gem'
11+
gem "bake-modernize"
12+
gem "bake-gem"
1313

14-
gem 'utopia-project'
14+
gem "utopia-project"
1515
end
1616

1717
group :test do

lib/protocol/rack.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2022, by Samuel Williams.
4+
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require_relative 'rack/version'
7-
require_relative 'rack/adapter'
8-
require_relative 'rack/request'
9-
require_relative 'rack/response'
6+
require_relative "rack/version"
7+
require_relative "rack/adapter"
8+
require_relative "rack/request"
9+
require_relative "rack/response"

lib/protocol/rack/adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Released under the MIT License.
44
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'rack'
6+
require "rack"
77

8-
require_relative 'adapter/rack2'
9-
require_relative 'adapter/rack3'
8+
require_relative "adapter/rack2"
9+
require_relative "adapter/rack3"
1010

1111
module Protocol
1212
module Rack

lib/protocol/rack/adapter/generic.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Released under the MIT License.
44
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'console'
6+
require "console"
77

8-
require_relative '../constants'
9-
require_relative '../input'
10-
require_relative '../response'
8+
require_relative "../constants"
9+
require_relative "../input"
10+
require_relative "../response"
1111

1212
module Protocol
1313
module Rack
@@ -66,7 +66,7 @@ def unwrap_headers(headers, env)
6666
# @parameter request [Protocol::HTTP::Request] The incoming request.
6767
# @parameter env [Hash] The rack `env`.
6868
def unwrap_request(request, env)
69-
if content_type = request.headers.delete('content-type')
69+
if content_type = request.headers.delete("content-type")
7070
env[CGI::CONTENT_TYPE] = content_type
7171
end
7272

@@ -78,7 +78,7 @@ def unwrap_request(request, env)
7878
self.unwrap_headers(request.headers, env)
7979

8080
# For the sake of compatibility, we set the `HTTP_UPGRADE` header to the requested protocol.
81-
if protocol = request.protocol and request.version.start_with?('HTTP/1')
81+
if protocol = request.protocol and request.version.start_with?("HTTP/1")
8282
env[CGI::HTTP_UPGRADE] = Array(protocol).join(",")
8383
end
8484

@@ -146,13 +146,13 @@ def failure_response(exception)
146146
def self.extract_protocol(env, response, headers)
147147
if protocol = response.protocol
148148
# This is the newer mechanism for protocol upgrade:
149-
if env['rack.protocol']
150-
headers['rack.protocol'] = protocol
149+
if env["rack.protocol"]
150+
headers["rack.protocol"] = protocol
151151

152152
# Older mechanism for protocol upgrade:
153153
elsif env[CGI::HTTP_UPGRADE]
154-
headers['upgrade'] = protocol
155-
headers['connection'] = 'upgrade'
154+
headers["upgrade"] = protocol
155+
headers["connection"] = "upgrade"
156156
end
157157
end
158158
end

lib/protocol/rack/adapter/rack2.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
# Released under the MIT License.
44
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'console'
6+
require "console"
77

8-
require_relative 'generic'
9-
require_relative '../rewindable'
8+
require_relative "generic"
9+
require_relative "../rewindable"
1010

1111
module Protocol
1212
module Rack
1313
module Adapter
1414
class Rack2 < Generic
15-
RACK_VERSION = 'rack.version'
16-
RACK_MULTITHREAD = 'rack.multithread'
17-
RACK_MULTIPROCESS = 'rack.multiprocess'
18-
RACK_RUN_ONCE = 'rack.run_once'
15+
RACK_VERSION = "rack.version"
16+
RACK_MULTITHREAD = "rack.multithread"
17+
RACK_MULTIPROCESS = "rack.multiprocess"
18+
RACK_RUN_ONCE = "rack.run_once"
1919

2020
def self.wrap(app)
2121
Rewindable.new(self.new(app))
2222
end
2323

2424
def make_environment(request)
25-
request_path, query_string = request.path.split('?', 2)
26-
server_name, server_port = (request.authority || '').split(':', 2)
25+
request_path, query_string = request.path.split("?", 2)
26+
server_name, server_port = (request.authority || "").split(":", 2)
2727

2828
env = {
2929
RACK_VERSION => [2, 0],
@@ -44,15 +44,15 @@ def make_environment(request)
4444
CGI::REQUEST_METHOD => request.method,
4545

4646
# The initial portion of the request URL's “path” that corresponds to the application object, so that the application knows its virtual “location”. This may be an empty string, if the application corresponds to the “root” of the server.
47-
CGI::SCRIPT_NAME => '',
47+
CGI::SCRIPT_NAME => "",
4848

4949
# The remainder of the request URL's “path”, designating the virtual “location” of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when originating from a URL.
5050
CGI::PATH_INFO => request_path,
5151
CGI::REQUEST_PATH => request_path,
5252
CGI::REQUEST_URI => request.path,
5353

5454
# The portion of the request URL that follows the ?, if any. May be empty, but is always required!
55-
CGI::QUERY_STRING => query_string || '',
55+
CGI::QUERY_STRING => query_string || "",
5656

5757
# The server protocol (e.g. HTTP/1.1):
5858
CGI::SERVER_PROTOCOL => request.version,
@@ -103,7 +103,7 @@ def wrap_headers(fields)
103103
fields.each do |key, value|
104104
key = key.downcase
105105

106-
if key.start_with?('rack.')
106+
if key.start_with?("rack.")
107107
meta[key] = value
108108
elsif value.is_a?(String)
109109
value.split("\n").each do |value|

lib/protocol/rack/adapter/rack3.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Released under the MIT License.
44
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'console'
6+
require "console"
77

8-
require_relative 'generic'
8+
require_relative "generic"
99

1010
module Protocol
1111
module Rack
@@ -20,8 +20,8 @@ def self.parse_file(...)
2020
end
2121

2222
def make_environment(request)
23-
request_path, query_string = request.path.split('?', 2)
24-
server_name, server_port = (request.authority || '').split(':', 2)
23+
request_path, query_string = request.path.split("?", 2)
24+
server_name, server_port = (request.authority || "").split(":", 2)
2525

2626
env = {
2727
PROTOCOL_HTTP_REQUEST => request,
@@ -40,15 +40,15 @@ def make_environment(request)
4040
CGI::REQUEST_METHOD => request.method,
4141

4242
# The initial portion of the request URL's “path” that corresponds to the application object, so that the application knows its virtual “location”. This may be an empty string, if the application corresponds to the “root” of the server.
43-
CGI::SCRIPT_NAME => '',
43+
CGI::SCRIPT_NAME => "",
4444

4545
# The remainder of the request URL's “path”, designating the virtual “location” of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when originating from a URL.
4646
CGI::PATH_INFO => request_path,
4747
CGI::REQUEST_PATH => request_path,
4848
CGI::REQUEST_URI => request.path,
4949

5050
# The portion of the request URL that follows the ?, if any. May be empty, but is always required!
51-
CGI::QUERY_STRING => query_string || '',
51+
CGI::QUERY_STRING => query_string || "",
5252

5353
# The server protocol (e.g. HTTP/1.1):
5454
CGI::SERVER_PROTOCOL => request.version,
@@ -75,7 +75,7 @@ def wrap_headers(fields)
7575
fields.each do |key, value|
7676
key = key.downcase
7777

78-
if key.start_with?('rack.')
78+
if key.start_with?("rack.")
7979
meta[key] = value
8080
elsif value.is_a?(Array)
8181
value.each do |value|

0 commit comments

Comments
 (0)