@@ -163,48 +163,33 @@ func TestHeaders(t *testing.T) {
163
163
164
164
ts , backend , root := newTestServerAndNode (t , nil , "ipns-hostname-redirects.car" )
165
165
backend .namesys ["/ipns/example.net" ] = newMockNamesysItem (path .NewIPFSPath (root ), time .Second * 30 )
166
+ backend .namesys ["/ipns/example.com" ] = newMockNamesysItem (path .NewIPFSPath (root ), time .Second * 55 )
167
+ backend .namesys ["/ipns/unknown.com" ] = newMockNamesysItem (path .NewIPFSPath (root ), 0 )
166
168
167
- t .Run ("UnixFS generated directory listing without index.html has no Cache-Control" , func (t * testing.T ) {
168
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net/" , nil )
169
- res := mustDoWithoutRedirect (t , req )
170
- require .Empty (t , res .Header ["Cache-Control" ])
171
- })
172
-
173
- t .Run ("UnixFS directory with index.html has Cache-Control" , func (t * testing.T ) {
174
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net/foo/" , nil )
175
- res := mustDoWithoutRedirect (t , req )
176
- require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
177
- })
178
-
179
- t .Run ("UnixFS file has Cache-Control" , func (t * testing.T ) {
180
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net/foo/index.html" , nil )
181
- res := mustDoWithoutRedirect (t , req )
182
- require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
183
- })
184
-
185
- t .Run ("Raw block has Cache-Control" , func (t * testing.T ) {
186
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net?format=raw" , nil )
187
- res := mustDoWithoutRedirect (t , req )
188
- require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
189
- })
190
-
191
- t .Run ("DAG-JSON block has Cache-Control" , func (t * testing.T ) {
192
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net?format=dag-json" , nil )
193
- res := mustDoWithoutRedirect (t , req )
194
- require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
195
- })
196
-
197
- t .Run ("DAG-CBOR block has Cache-Control" , func (t * testing.T ) {
198
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net?format=dag-cbor" , nil )
199
- res := mustDoWithoutRedirect (t , req )
200
- require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
201
- })
169
+ testCases := []struct {
170
+ path string
171
+ cacheControl string
172
+ }{
173
+ {"/ipns/example.net/" , "public, max-age=30" }, // As generated directory listing
174
+ {"/ipns/example.com/" , "public, max-age=55" }, // As generated directory listing (different)
175
+ {"/ipns/unknown.com/" , "" }, // As generated directory listing (unknown)
176
+ {"/ipns/example.net/foo/" , "public, max-age=30" }, // As index.html directory listing
177
+ {"/ipns/example.net/foo/index.html" , "public, max-age=30" }, // As deserialized UnixFS file
178
+ {"/ipns/example.net/?format=raw" , "public, max-age=30" }, // As Raw block
179
+ {"/ipns/example.net/?format=dag-json" , "public, max-age=30" }, // As DAG-JSON block
180
+ {"/ipns/example.net/?format=dag-cbor" , "public, max-age=30" }, // As DAG-CBOR block
181
+ {"/ipns/example.net/?format=car" , "public, max-age=30" }, // As CAR block
182
+ }
202
183
203
- t . Run ( "CAR block has Cache-Control" , func ( t * testing. T ) {
204
- req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipns/example.net?format=car" , nil )
184
+ for _ , testCase := range testCases {
185
+ req := mustNewRequest (t , http .MethodGet , ts .URL + testCase . path , nil )
205
186
res := mustDoWithoutRedirect (t , req )
206
- require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
207
- })
187
+ if testCase .cacheControl == "" {
188
+ assert .Empty (t , res .Header ["Cache-Control" ])
189
+ } else {
190
+ assert .Equal (t , testCase .cacheControl , res .Header .Get ("Cache-Control" ))
191
+ }
192
+ }
208
193
})
209
194
210
195
t .Run ("Cache-Control is not immutable on generated /ipfs/ HTML dir listings" , func (t * testing.T ) {
0 commit comments