Skip to content

Commit 5f186a0

Browse files
committed
Modernize gem.
1 parent 5c97180 commit 5f186a0

17 files changed

+94
-95
lines changed

.github/workflows/documentation-coverage.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v4
1818
- uses: ruby/setup-ruby@v1
1919
with:
20-
ruby-version: "3.3"
20+
ruby-version: "3.4"
2121
bundler-cache: true
2222

2323
- name: Validate coverage

.github/workflows/documentation.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
- uses: ruby/setup-ruby@v1
3131
with:
32-
ruby-version: "3.3"
32+
ruby-version: "3.4"
3333
bundler-cache: true
3434

3535
- name: Installing packages

.github/workflows/rubocop.yaml

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test External
1+
name: RuboCop
22

33
on: [push, pull_request]
44

@@ -9,26 +9,14 @@ env:
99
CONSOLE_OUTPUT: XTerm
1010

1111
jobs:
12-
test:
13-
name: ${{matrix.ruby}} on ${{matrix.os}}
14-
runs-on: ${{matrix.os}}-latest
15-
16-
strategy:
17-
matrix:
18-
os:
19-
- ubuntu
20-
- macos
21-
22-
ruby:
23-
- "3.1"
24-
- "3.2"
25-
- "3.3"
12+
check:
13+
runs-on: ubuntu-latest
2614

2715
steps:
2816
- uses: actions/checkout@v4
2917
- uses: ruby/setup-ruby@v1
3018
with:
31-
ruby-version: ${{matrix.ruby}}
19+
ruby-version: ruby
3220
bundler-cache: true
3321

3422
- name: Run RuboCop

.github/workflows/test-coverage.yaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- macos
2222

2323
ruby:
24-
- "3.3"
24+
- "3.4"
2525

2626
steps:
2727
- uses: actions/checkout@v4
@@ -33,9 +33,11 @@ jobs:
3333
- name: Run tests
3434
timeout-minutes: 5
3535
run: bundle exec bake test
36-
37-
- uses: actions/upload-artifact@v3
36+
37+
- uses: actions/upload-artifact@v4
3838
with:
39+
include-hidden-files: true
40+
if-no-files-found: error
3941
name: coverage-${{matrix.os}}-${{matrix.ruby}}
4042
path: .covered.db
4143

@@ -47,10 +49,10 @@ jobs:
4749
- uses: actions/checkout@v4
4850
- uses: ruby/setup-ruby@v1
4951
with:
50-
ruby-version: "3.3"
52+
ruby-version: "3.4"
5153
bundler-cache: true
5254

53-
- uses: actions/download-artifact@v3
55+
- uses: actions/download-artifact@v4
5456

5557
- name: Validate coverage
5658
timeout-minutes: 5

.github/workflows/test-external.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- "3.1"
2424
- "3.2"
2525
- "3.3"
26+
- "3.4"
2627

2728
steps:
2829
- uses: actions/checkout@v4

.github/workflows/test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- "3.1"
2525
- "3.2"
2626
- "3.3"
27+
- "3.4"
2728

2829
experimental: [false]
2930

.rubocop.yml

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Layout/IndentationConsistency:
1616
Enabled: true
1717
EnforcedStyle: normal
1818

19+
Layout/BlockAlignment:
20+
Enabled: true
21+
1922
Layout/EndAlignment:
2023
Enabled: true
2124
EnforcedStyleAlignWith: start_of_line
@@ -44,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:
4447

4548
Style/FrozenStringLiteralComment:
4649
Enabled: true
50+
51+
Style/StringLiterals:
52+
Enabled: true
53+
EnforcedStyle: double_quotes

async-http-cache.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Gem::Specification.new do |spec|
1010
spec.authors = ["Samuel Williams", "Colin Kelley", "Olle Jonsson"]
1111
spec.license = "MIT"
1212

13-
spec.cert_chain = ['release.cert']
14-
spec.signing_key = File.expand_path('~/.gem/release.pem')
13+
spec.cert_chain = ["release.cert"]
14+
spec.signing_key = File.expand_path("~/.gem/release.pem")
1515

1616
spec.homepage = "https://github.com/socketry/async-http-cache"
1717

1818
spec.metadata = {
1919
"source_code_uri" => "https://github.com/socketry/async-http-cache.git",
2020
}
2121

22-
spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
22+
spec.files = Dir.glob(["{lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)
2323

2424
spec.required_ruby_version = ">= 3.1"
2525

fixtures/async/http/cache/a_general_cache.rb

+28-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright, 2020-2024, by Samuel Williams.
55
# Copyright, 2022, by Colin Kelley.
66

7-
require 'async/http/cache/general'
7+
require "async/http/cache/general"
88

99
module Async::HTTP::Cache
1010
AGeneralCache = Sus::Shared("a general cache") do
@@ -50,13 +50,13 @@ module Async::HTTP::Cache
5050
expect(cache).to have_attributes(count: be == 0)
5151
end
5252

53-
with 'varied response' do
53+
with "varied response" do
5454
let(:app) do
5555
Protocol::HTTP::Middleware.for do |request|
56-
response = if user_agent = request.headers['user-agent']
57-
Protocol::HTTP::Response[200, [['cache-control', 'max-age=1, public'], ['vary', 'user-agent']], [user_agent]]
56+
response = if user_agent = request.headers["user-agent"]
57+
Protocol::HTTP::Response[200, [["cache-control", "max-age=1, public"], ["vary", "user-agent"]], [user_agent]]
5858
else
59-
Protocol::HTTP::Response[200, [['cache-control', 'max-age=1, public'], ['vary', 'user-agent']], ['Hello', ' ', 'World']]
59+
Protocol::HTTP::Response[200, [["cache-control", "max-age=1, public"], ["vary", "user-agent"]], ["Hello", " ", "World"]]
6060
end
6161

6262
if request.head?
@@ -68,15 +68,15 @@ module Async::HTTP::Cache
6868
end
6969

7070
let(:user_agents) {[
71-
'test-a',
72-
'test-b',
71+
"test-a",
72+
"test-b",
7373
]}
7474

7575
it "should cache GET requests" do
7676
2.times do
7777
user_agents.each do |user_agent|
78-
response = client.get("/", {'user-agent' => user_agent})
79-
expect(response.headers['vary']).to be(:include?, 'user-agent')
78+
response = client.get("/", {"user-agent" => user_agent})
79+
expect(response.headers["vary"]).to be(:include?, "user-agent")
8080
expect(response.read).to be == user_agent
8181
end
8282
end
@@ -85,24 +85,24 @@ module Async::HTTP::Cache
8585
end
8686
end
8787

88-
with 'cache writes' do
89-
with 'response code' do
88+
with "cache writes" do
89+
with "response code" do
9090
let(:app) do
9191
Protocol::HTTP::Middleware.for do |_request|
92-
Protocol::HTTP::Response[response_code, [], ['body']]
92+
Protocol::HTTP::Response[response_code, [], ["body"]]
9393
end
9494
end
9595

9696
[200, 203, 300, 301, 302, 404, 410].each do |response_code|
9797
with "cacheable response code #{response_code}", unique: "status-#{response_code}" do
9898
let(:response_code) {response_code}
9999

100-
it 'is cached' do
100+
it "is cached" do
101101
responses = 2.times.map {client.get("/", {}).tap(&:finish)}
102102
headers = responses.map {|r| r.headers.to_h}
103103

104-
expect(headers.first).not.to be(:include?, 'x-cache')
105-
expect(headers.last).to have_keys('x-cache' => be == ['hit'])
104+
expect(headers.first).not.to be(:include?, "x-cache")
105+
expect(headers.last).to have_keys("x-cache" => be == ["hit"])
106106
end
107107
end
108108
end
@@ -111,7 +111,7 @@ module Async::HTTP::Cache
111111
with "not cacheable response code #{response_code}", unique: "status-#{response_code}" do
112112
let(:response_code) {response_code}
113113

114-
it 'is not cached' do
114+
it "is not cached" do
115115
responses = 2.times.map {client.get("/", {}).tap(&:finish)}
116116
response_headers = responses.map {|r| r.headers.to_h}
117117

@@ -121,19 +121,19 @@ module Async::HTTP::Cache
121121
end
122122
end
123123

124-
with 'by cache-control: flag' do
124+
with "by cache-control: flag" do
125125
let(:app) do
126126
Protocol::HTTP::Middleware.for do |_request|
127127
Protocol::HTTP::Response[200, headers] # no body?
128128
end
129129
end
130130

131-
['no-store', 'private'].each do |flag|
132-
let(:headers) {[['cache-control', flag]]}
131+
["no-store", "private"].each do |flag|
132+
let(:headers) {[["cache-control", flag]]}
133133
let(:headers_hash) {Hash[headers.map {|k, v| [k, [v]]}]}
134134

135135
with "not cacheable response #{flag}", unique: flag do
136-
it 'is not cached' do
136+
it "is not cached" do
137137
responses = 2.times.map {client.get("/", {}).tap(&:finish)}
138138
response_headers = responses.map {|r| r.headers.to_h}
139139

@@ -142,10 +142,10 @@ module Async::HTTP::Cache
142142
end
143143
end
144144

145-
with 'cacheable response' do
145+
with "cacheable response" do
146146
let(:headers) {[]}
147147

148-
it 'is cached' do
148+
it "is cached" do
149149
responses = 2.times.map {client.get("/", {}).tap(&:finish)}
150150
headers = responses.map {|r| r.headers.to_h}
151151

@@ -155,17 +155,17 @@ module Async::HTTP::Cache
155155
end
156156
end
157157

158-
with 'if-none-match' do
159-
it 'validate etag' do
158+
with "if-none-match" do
159+
it "validate etag" do
160160
# First, warm up the cache:
161161
response = client.get("/")
162-
expect(response.headers).not.to be(:include?, 'etag')
162+
expect(response.headers).not.to be(:include?, "etag")
163163
expect(response.read).to be == "Hello World"
164-
expect(response.headers).to be(:include?, 'etag')
164+
expect(response.headers).to be(:include?, "etag")
165165

166-
etag = response.headers['etag']
166+
etag = response.headers["etag"]
167167

168-
response = client.get("/", {'if-none-match' => etag})
168+
response = client.get("/", {"if-none-match" => etag})
169169
expect(response).to be(:not_modified?)
170170
end
171171
end

lib/async/http/cache/body.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
# Released under the MIT License.
44
# Copyright, 2020-2024, by Samuel Williams.
55

6-
require 'protocol/http/body/rewindable'
7-
require 'protocol/http/body/completable'
8-
require 'protocol/http/body/digestable'
6+
require "protocol/http/body/rewindable"
7+
require "protocol/http/body/completable"
8+
require "protocol/http/body/digestable"
99

10-
require 'console'
11-
require 'console/event/failure'
10+
require "console"
11+
require "console/event/failure"
1212

1313
module Async
1414
module HTTP
1515
module Cache
1616
module Body
17-
TRAILER = 'trailer'
18-
ETAG = 'etag'
17+
TRAILER = "trailer"
18+
ETAG = "etag"
1919

2020
def self.wrap(response, &block)
2121
if body = response.body

lib/async/http/cache/general.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
# Copyright, 2020-2024, by Samuel Williams.
55
# Copyright, 2022, by Colin Kelley.
66

7-
require 'set'
8-
require 'protocol/http/middleware'
7+
require "set"
8+
require "protocol/http/middleware"
99

10-
require_relative 'body'
11-
require_relative 'response'
12-
require_relative 'store'
10+
require_relative "body"
11+
require_relative "response"
12+
require_relative "store"
1313

1414
module Async
1515
module HTTP
1616
module Cache
1717
# Implements a general shared cache according to https://www.rfc-editor.org/rfc/rfc9111
1818
class General < ::Protocol::HTTP::Middleware
19-
CACHE_CONTROL = 'cache-control'
19+
CACHE_CONTROL = "cache-control"
2020

21-
CONTENT_TYPE = 'content-type'
22-
AUTHORIZATION = 'authorization'
23-
COOKIE = 'cookie'
24-
SET_COOKIE = 'set-cookie'
21+
CONTENT_TYPE = "content-type"
22+
AUTHORIZATION = "authorization"
23+
COOKIE = "cookie"
24+
SET_COOKIE = "set-cookie"
2525

2626
# Status codes of responses that MAY be stored by a cache or used in reply
2727
# to a subsequent request.
@@ -72,7 +72,7 @@ def cacheable_request?(request)
7272
end
7373

7474
# We only support caching GET and HEAD requests:
75-
unless request.method == 'GET' || request.method == 'HEAD'
75+
unless request.method == "GET" || request.method == "HEAD"
7676
return false
7777
end
7878

@@ -111,7 +111,7 @@ def cacheable_response?(response)
111111
Console.logger.debug(self, status: response.status) {"Cannot cache response with status code!"}
112112
return false
113113
end
114-
114+
115115
unless cacheable_response_headers?(response.headers)
116116
Console.logger.debug(self) {"Cannot cache response with uncacheable headers!"}
117117
return false
@@ -137,7 +137,7 @@ def wrap(key, request, response)
137137
if request.head? and body = response.body
138138
unless body.empty?
139139
Console.logger.warn(self) {"HEAD request resulted in non-empty body!"}
140-
140+
141141
return response
142142
end
143143
end
@@ -161,7 +161,7 @@ def wrap(key, request, response)
161161
end
162162
end
163163
end
164-
164+
165165
def call(request)
166166
cache_control = request.headers[CACHE_CONTROL]
167167

0 commit comments

Comments
 (0)