@@ -37,19 +37,19 @@ func TestGatewayGet(t *testing.T) {
37
37
return p
38
38
}
39
39
40
- backend .namesys ["/ipns/example.com" ] = path .NewIPFSPath (k .Cid ())
41
- backend .namesys ["/ipns/working.example.com" ] = k
42
- backend .namesys ["/ipns/double.example.com" ] = mustMakeDNSLinkPath ("working.example.com" )
43
- backend .namesys ["/ipns/triple.example.com" ] = mustMakeDNSLinkPath ("double.example.com" )
44
- backend .namesys ["/ipns/broken.example.com" ] = mustMakeDNSLinkPath (k .Cid ().String ())
40
+ backend .namesys ["/ipns/example.com" ] = newMockNamesysItem ( path .NewIPFSPath (k .Cid ()), 0 )
41
+ backend .namesys ["/ipns/working.example.com" ] = newMockNamesysItem ( k , 0 )
42
+ backend .namesys ["/ipns/double.example.com" ] = newMockNamesysItem ( mustMakeDNSLinkPath ("working.example.com" ), 0 )
43
+ backend .namesys ["/ipns/triple.example.com" ] = newMockNamesysItem ( mustMakeDNSLinkPath ("double.example.com" ), 0 )
44
+ backend .namesys ["/ipns/broken.example.com" ] = newMockNamesysItem ( mustMakeDNSLinkPath (k .Cid ().String ()), 0 )
45
45
// We picked .man because:
46
46
// 1. It's a valid TLD.
47
47
// 2. Go treats it as the file extension for "man" files (even though
48
48
// nobody actually *uses* this extension, AFAIK).
49
49
//
50
50
// Unfortunately, this may not work on all platforms as file type
51
51
// detection is platform dependent.
52
- backend .namesys ["/ipns/example.man" ] = k
52
+ backend .namesys ["/ipns/example.man" ] = newMockNamesysItem ( k , 0 )
53
53
54
54
for _ , test := range []struct {
55
55
host string
@@ -98,7 +98,7 @@ func TestPretty404(t *testing.T) {
98
98
t .Logf ("test server url: %s" , ts .URL )
99
99
100
100
host := "example.net"
101
- backend .namesys ["/ipns/" + host ] = path .NewIPFSPath (root )
101
+ backend .namesys ["/ipns/" + host ] = newMockNamesysItem ( path .NewIPFSPath (root ), 0 )
102
102
103
103
for _ , test := range []struct {
104
104
path string
@@ -158,7 +158,56 @@ func TestHeaders(t *testing.T) {
158
158
dagCborRoots = dirRoots + "," + dagCborCID
159
159
)
160
160
161
- t .Run ("Cache-Control is not immutable on generated /ipfs/ HTML dir listings" , func (t * testing.T ) {
161
+ t .Run ("Cache-Control uses TTL for /ipns/ when it is known" , func (t * testing.T ) {
162
+ t .Parallel ()
163
+
164
+ ts , backend , root := newTestServerAndNode (t , nil , "ipns-hostname-redirects.car" )
165
+ backend .namesys ["/ipns/example.net" ] = newMockNamesysItem (path .NewIPFSPath (root ), time .Second * 30 )
166
+
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
+ })
202
+
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 )
205
+ res := mustDoWithoutRedirect (t , req )
206
+ require .Equal (t , "public, max-age=30" , res .Header .Get ("Cache-Control" ))
207
+ })
208
+ })
209
+
210
+ t .Run ("Cache-Control is not immutable on generated /ipfs/ HTML dir listings" , func (t * testing.T ) {
162
211
req := mustNewRequest (t , http .MethodGet , ts .URL + "/ipfs/" + rootCID + "/" , nil )
163
212
res := mustDoWithoutRedirect (t , req )
164
213
@@ -500,7 +549,7 @@ func TestRedirects(t *testing.T) {
500
549
t .Parallel ()
501
550
502
551
ts , backend , root := newTestServerAndNode (t , nil , "ipns-hostname-redirects.car" )
503
- backend .namesys ["/ipns/example.net" ] = path .NewIPFSPath (root )
552
+ backend .namesys ["/ipns/example.net" ] = newMockNamesysItem ( path .NewIPFSPath (root ), 0 )
504
553
505
554
// make request to directory containing index.html
506
555
req := mustNewRequest (t , http .MethodGet , ts .URL + "/foo" , nil )
@@ -535,7 +584,7 @@ func TestRedirects(t *testing.T) {
535
584
t .Parallel ()
536
585
537
586
backend , root := newMockBackend (t , "redirects-spa.car" )
538
- backend .namesys ["/ipns/example.com" ] = path .NewIPFSPath (root )
587
+ backend .namesys ["/ipns/example.com" ] = newMockNamesysItem ( path .NewIPFSPath (root ), 0 )
539
588
540
589
ts := newTestServerWithConfig (t , backend , Config {
541
590
Headers : map [string ][]string {},
@@ -672,8 +721,8 @@ func TestDeserializedResponses(t *testing.T) {
672
721
t .Parallel ()
673
722
674
723
backend , root := newMockBackend (t , "fixtures.car" )
675
- backend .namesys ["/ipns/trustless.com" ] = path .NewIPFSPath (root )
676
- backend .namesys ["/ipns/trusted.com" ] = path .NewIPFSPath (root )
724
+ backend .namesys ["/ipns/trustless.com" ] = newMockNamesysItem ( path .NewIPFSPath (root ), 0 )
725
+ backend .namesys ["/ipns/trusted.com" ] = newMockNamesysItem ( path .NewIPFSPath (root ), 0 )
677
726
678
727
ts := newTestServerWithConfig (t , backend , Config {
679
728
Headers : map [string ][]string {},
@@ -735,8 +784,8 @@ func (mb *errorMockBackend) GetCAR(ctx context.Context, path path.ImmutablePath,
735
784
return ContentPathMetadata {}, nil , mb .err
736
785
}
737
786
738
- func (mb * errorMockBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
739
- return nil , mb .err
787
+ func (mb * errorMockBackend ) ResolveMutable (ctx context.Context , path path.Path ) (path.ImmutablePath , time. Duration , error ) {
788
+ return nil , 0 , mb .err
740
789
}
741
790
742
791
func (mb * errorMockBackend ) GetIPNSRecord (ctx context.Context , c cid.Cid ) ([]byte , error ) {
@@ -819,7 +868,7 @@ func (mb *panicMockBackend) GetCAR(ctx context.Context, immutablePath path.Immut
819
868
panic ("i am panicking" )
820
869
}
821
870
822
- func (mb * panicMockBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
871
+ func (mb * panicMockBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , time. Duration , error ) {
823
872
panic ("i am panicking" )
824
873
}
825
874
0 commit comments