@@ -34,6 +34,7 @@ import (
3434 cidlink "github.com/ipld/go-ipld-prime/linking/cid"
3535 "github.com/ipld/go-ipld-prime/storage/memstore"
3636 selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse"
37+ trustlesshttp "github.com/ipld/go-trustless-utils/http"
3738 "github.com/ipld/go-trustless-utils/traversal"
3839 "github.com/libp2p/go-libp2p/core/peer"
3940 "github.com/multiformats/go-multicodec"
@@ -79,6 +80,7 @@ func TestHttpFetch(t *testing.T) {
7980 modifyQueries []queryModifier
8081 validateBodies []bodyValidator
8182 lassieOpts lassieOptsGen
83+ expectNoDups bool
8284 }{
8385 {
8486 name : "graphsync large sharded file" ,
@@ -904,9 +906,57 @@ func TestHttpFetch(t *testing.T) {
904906 }},
905907 },
906908 {
907- name : "http large sharded file with dups, no dups response requested" ,
909+ name : "http large sharded file with dups, no dups response requested" ,
910+ httpRemotes : 1 ,
911+ setHeader : noDups ,
912+ expectNoDups : true ,
913+ generate : func (t * testing.T , rndReader io.Reader , remotes []testpeer.TestPeer ) []unixfs.DirEntry {
914+ return []unixfs.DirEntry {unixfs .GenerateFile (t , remotes [0 ].LinkSystem , testutil.ZeroReader {}, 4 << 20 )}
915+ },
916+ validateBodies : []bodyValidator {func (t * testing.T , srcData unixfs.DirEntry , body []byte ) {
917+ wantCids := []cid.Cid {
918+ srcData .Root , // "/""
919+ srcData .SelfCids [1 ],
920+ srcData .SelfCids [len (srcData .SelfCids )- 1 ],
921+ }
922+ validateCarBody (t , body , srcData .Root , wantCids , true )
923+ }},
924+ },
925+ {
926+ name : "http large sharded file with dups, */* gives dups" ,
908927 httpRemotes : 1 ,
909- setHeader : noDups ,
928+ setHeader : func (h http.Header ) { h .Set ("Accept" , "*/*" ) },
929+ generate : func (t * testing.T , rndReader io.Reader , remotes []testpeer.TestPeer ) []unixfs.DirEntry {
930+ return []unixfs.DirEntry {unixfs .GenerateFile (t , remotes [0 ].LinkSystem , testutil.ZeroReader {}, 4 << 20 )}
931+ },
932+ validateBodies : []bodyValidator {func (t * testing.T , srcData unixfs.DirEntry , body []byte ) {
933+ store := & testutil.CorrectedMemStore {ParentStore : & memstore.Store {
934+ Bag : make (map [string ][]byte ),
935+ }}
936+ lsys := cidlink .DefaultLinkSystem ()
937+ lsys .SetReadStorage (store )
938+ lsys .SetWriteStorage (store )
939+ _ , err := traversal.Config {
940+ Root : srcData .Root ,
941+ Selector : selectorparse .CommonSelector_ExploreAllRecursively ,
942+ ExpectDuplicatesIn : true ,
943+ }.VerifyCar (context .Background (), bytes .NewReader (body ), lsys )
944+ require .NoError (t , err )
945+ }},
946+ }, {
947+ name : "http large sharded file with dups, multiple accept, priority to no dups" ,
948+ httpRemotes : 1 ,
949+ expectNoDups : true ,
950+ setHeader : func (h http.Header ) {
951+ h .Set ("Accept" ,
952+ strings .Join ([]string {
953+ "text/html" ,
954+ trustlesshttp .DefaultContentType ().WithDuplicates (true ).WithQuality (0.7 ).String (),
955+ trustlesshttp .DefaultContentType ().WithDuplicates (false ).WithQuality (0.8 ).String (),
956+ "*/*;q=0.1" ,
957+ }, ", " ),
958+ )
959+ },
910960 generate : func (t * testing.T , rndReader io.Reader , remotes []testpeer.TestPeer ) []unixfs.DirEntry {
911961 return []unixfs.DirEntry {unixfs .GenerateFile (t , remotes [0 ].LinkSystem , testutil.ZeroReader {}, 4 << 20 )}
912962 },
@@ -919,6 +969,37 @@ func TestHttpFetch(t *testing.T) {
919969 validateCarBody (t , body , srcData .Root , wantCids , true )
920970 }},
921971 },
972+ {
973+ name : "http large sharded file with dups, multiple accept, priority to dups" ,
974+ httpRemotes : 1 ,
975+ setHeader : func (h http.Header ) {
976+ h .Set ("Accept" ,
977+ strings .Join ([]string {
978+ "text/html" ,
979+ trustlesshttp .DefaultContentType ().WithDuplicates (true ).WithQuality (0.8 ).String (),
980+ trustlesshttp .DefaultContentType ().WithDuplicates (false ).WithQuality (0.7 ).String (),
981+ "*/*;q=0.1" ,
982+ }, ", " ),
983+ )
984+ },
985+ generate : func (t * testing.T , rndReader io.Reader , remotes []testpeer.TestPeer ) []unixfs.DirEntry {
986+ return []unixfs.DirEntry {unixfs .GenerateFile (t , remotes [0 ].LinkSystem , testutil.ZeroReader {}, 4 << 20 )}
987+ },
988+ validateBodies : []bodyValidator {func (t * testing.T , srcData unixfs.DirEntry , body []byte ) {
989+ store := & testutil.CorrectedMemStore {ParentStore : & memstore.Store {
990+ Bag : make (map [string ][]byte ),
991+ }}
992+ lsys := cidlink .DefaultLinkSystem ()
993+ lsys .SetReadStorage (store )
994+ lsys .SetWriteStorage (store )
995+ _ , err := traversal.Config {
996+ Root : srcData .Root ,
997+ Selector : selectorparse .CommonSelector_ExploreAllRecursively ,
998+ ExpectDuplicatesIn : true ,
999+ }.VerifyCar (context .Background (), bytes .NewReader (body ), lsys )
1000+ require .NoError (t , err )
1001+ }},
1002+ },
9221003 {
9231004 name : "bitswap nested file, path with special characters" ,
9241005 bitswapRemotes : 1 ,
@@ -1141,9 +1222,7 @@ func TestHttpFetch(t *testing.T) {
11411222 req .Equal (fmt .Sprintf (`attachment; filename="%s.car"` , srcData [i ].Root .String ()), resp .Header .Get ("Content-Disposition" ))
11421223 req .Equal ("none" , resp .Header .Get ("Accept-Ranges" ))
11431224 req .Equal ("public, max-age=29030400, immutable" , resp .Header .Get ("Cache-Control" ))
1144- ct := resp .Header .Get ("Content-Type" )
1145- // TODO: check the noDups() case and assert accordingly
1146- req .Equal ("application/vnd.ipld.car; version=1; order=dfs; dups=" , ct [:len (ct )- 1 ]) // strip off y|n from the end
1225+ req .Equal (trustlesshttp .DefaultContentType ().WithDuplicates (! testCase .expectNoDups ).String (), resp .Header .Get ("Content-Type" ))
11471226 req .Equal ("nosniff" , resp .Header .Get ("X-Content-Type-Options" ))
11481227 etagStart := fmt .Sprintf (`"%s.car.` , srcData [i ].Root .String ())
11491228 etagGot := resp .Header .Get ("ETag" )
0 commit comments