4
4
# Copyright, 2020-2024, by Samuel Williams.
5
5
# Copyright, 2022, by Colin Kelley.
6
6
7
- require ' async/http/cache/general'
7
+ require " async/http/cache/general"
8
8
9
9
module Async ::HTTP ::Cache
10
10
AGeneralCache = Sus ::Shared ( "a general cache" ) do
@@ -50,13 +50,13 @@ module Async::HTTP::Cache
50
50
expect ( cache ) . to have_attributes ( count : be == 0 )
51
51
end
52
52
53
- with ' varied response' do
53
+ with " varied response" do
54
54
let ( :app ) do
55
55
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 ] ]
58
58
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" ] ]
60
60
end
61
61
62
62
if request . head?
@@ -68,15 +68,15 @@ module Async::HTTP::Cache
68
68
end
69
69
70
70
let ( :user_agents ) { [
71
- ' test-a' ,
72
- ' test-b' ,
71
+ " test-a" ,
72
+ " test-b" ,
73
73
] }
74
74
75
75
it "should cache GET requests" do
76
76
2 . times do
77
77
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" )
80
80
expect ( response . read ) . to be == user_agent
81
81
end
82
82
end
@@ -85,24 +85,24 @@ module Async::HTTP::Cache
85
85
end
86
86
end
87
87
88
- with ' cache writes' do
89
- with ' response code' do
88
+ with " cache writes" do
89
+ with " response code" do
90
90
let ( :app ) do
91
91
Protocol ::HTTP ::Middleware . for do |_request |
92
- Protocol ::HTTP ::Response [ response_code , [ ] , [ ' body' ] ]
92
+ Protocol ::HTTP ::Response [ response_code , [ ] , [ " body" ] ]
93
93
end
94
94
end
95
95
96
96
[ 200 , 203 , 300 , 301 , 302 , 404 , 410 ] . each do |response_code |
97
97
with "cacheable response code #{ response_code } " , unique : "status-#{ response_code } " do
98
98
let ( :response_code ) { response_code }
99
99
100
- it ' is cached' do
100
+ it " is cached" do
101
101
responses = 2 . times . map { client . get ( "/" , { } ) . tap ( &:finish ) }
102
102
headers = responses . map { |r | r . headers . to_h }
103
103
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" ] )
106
106
end
107
107
end
108
108
end
@@ -111,7 +111,7 @@ module Async::HTTP::Cache
111
111
with "not cacheable response code #{ response_code } " , unique : "status-#{ response_code } " do
112
112
let ( :response_code ) { response_code }
113
113
114
- it ' is not cached' do
114
+ it " is not cached" do
115
115
responses = 2 . times . map { client . get ( "/" , { } ) . tap ( &:finish ) }
116
116
response_headers = responses . map { |r | r . headers . to_h }
117
117
@@ -121,19 +121,19 @@ module Async::HTTP::Cache
121
121
end
122
122
end
123
123
124
- with ' by cache-control: flag' do
124
+ with " by cache-control: flag" do
125
125
let ( :app ) do
126
126
Protocol ::HTTP ::Middleware . for do |_request |
127
127
Protocol ::HTTP ::Response [ 200 , headers ] # no body?
128
128
end
129
129
end
130
130
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 ] ] }
133
133
let ( :headers_hash ) { Hash [ headers . map { |k , v | [ k , [ v ] ] } ] }
134
134
135
135
with "not cacheable response #{ flag } " , unique : flag do
136
- it ' is not cached' do
136
+ it " is not cached" do
137
137
responses = 2 . times . map { client . get ( "/" , { } ) . tap ( &:finish ) }
138
138
response_headers = responses . map { |r | r . headers . to_h }
139
139
@@ -142,10 +142,10 @@ module Async::HTTP::Cache
142
142
end
143
143
end
144
144
145
- with ' cacheable response' do
145
+ with " cacheable response" do
146
146
let ( :headers ) { [ ] }
147
147
148
- it ' is cached' do
148
+ it " is cached" do
149
149
responses = 2 . times . map { client . get ( "/" , { } ) . tap ( &:finish ) }
150
150
headers = responses . map { |r | r . headers . to_h }
151
151
@@ -155,17 +155,17 @@ module Async::HTTP::Cache
155
155
end
156
156
end
157
157
158
- with ' if-none-match' do
159
- it ' validate etag' do
158
+ with " if-none-match" do
159
+ it " validate etag" do
160
160
# First, warm up the cache:
161
161
response = client . get ( "/" )
162
- expect ( response . headers ) . not . to be ( :include? , ' etag' )
162
+ expect ( response . headers ) . not . to be ( :include? , " etag" )
163
163
expect ( response . read ) . to be == "Hello World"
164
- expect ( response . headers ) . to be ( :include? , ' etag' )
164
+ expect ( response . headers ) . to be ( :include? , " etag" )
165
165
166
- etag = response . headers [ ' etag' ]
166
+ etag = response . headers [ " etag" ]
167
167
168
- response = client . get ( "/" , { ' if-none-match' => etag } )
168
+ response = client . get ( "/" , { " if-none-match" => etag } )
169
169
expect ( response ) . to be ( :not_modified? )
170
170
end
171
171
end
0 commit comments