From f0a3a131d7e5e031d9fb336425b4bc76b206b96b Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 7 Sep 2023 15:23:57 +1000 Subject: [PATCH] chore: update to go-trustless-utils@0.2 --- go.mod | 6 +++--- go.sum | 12 ++++++------ httpipfs.go | 6 +++--- httpipfs_test.go | 14 +++++++------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index df1112a..fc136d9 100644 --- a/go.mod +++ b/go.mod @@ -10,10 +10,10 @@ require ( github.com/ipfs/go-ipld-format v0.6.0 github.com/ipfs/go-log/v2 v2.5.1 github.com/ipfs/go-unixfsnode v1.8.0 - github.com/ipld/go-car/v2 v2.13.0 + github.com/ipld/go-car/v2 v2.13.1 github.com/ipld/go-ipld-prime v0.21.0 - github.com/ipld/go-trustless-utils v0.0.0 - github.com/ipld/ipld/specs v0.0.0-20230826120441-91918996e8eb + github.com/ipld/go-trustless-utils v0.1.1-0.20230907055204-83d1e838c1c1 + github.com/ipld/ipld/specs v0.0.0-20230907004443-0e4ff95ff474 github.com/ipni/go-libipni v0.3.4 github.com/ipni/index-provider v0.13.5 github.com/libp2p/go-libp2p v0.30.0 diff --git a/go.sum b/go.sum index 2545ad9..78ae889 100644 --- a/go.sum +++ b/go.sum @@ -271,8 +271,8 @@ github.com/ipfs/go-unixfs v0.4.4 h1:D/dLBOJgny5ZLIur2vIXVQVW0EyDHdOMBDEhgHrt6rY= github.com/ipfs/go-unixfsnode v1.8.0 h1:yCkakzuE365glu+YkgzZt6p38CSVEBPgngL9ZkfnyQU= github.com/ipfs/go-unixfsnode v1.8.0/go.mod h1:HxRu9HYHOjK6HUqFBAi++7DVoWAHn0o4v/nZ/VA+0g8= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= -github.com/ipld/go-car/v2 v2.13.0 h1:ogsB0rm6cclI2/HxP2XM+z+KehNj2ovpz0YfiF1hJwE= -github.com/ipld/go-car/v2 v2.13.0/go.mod h1:QkdjjFNGit2GIkpQ953KBwowuoukoM75nP/JI1iDJdo= +github.com/ipld/go-car/v2 v2.13.1 h1:KnlrKvEPEzr5IZHKTXLAEub+tPrzeAFQVRlSQvuxBO4= +github.com/ipld/go-car/v2 v2.13.1/go.mod h1:QkdjjFNGit2GIkpQ953KBwowuoukoM75nP/JI1iDJdo= github.com/ipld/go-codec-dagpb v1.6.0 h1:9nYazfyu9B1p3NAgfVdpRco3Fs2nFC72DqVsMj6rOcc= github.com/ipld/go-codec-dagpb v1.6.0/go.mod h1:ANzFhfP2uMJxRBr8CE+WQWs5UsNa0pYtmKZ+agnUw9s= github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0 h1:QAI/Ridj0+foHD6epbxmB4ugxz9B4vmNdYSmQLGa05E= @@ -280,10 +280,10 @@ github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0/go.mod h1:od github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E= github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ= github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo= -github.com/ipld/go-trustless-utils v0.0.0 h1:X+hY7lWZSd6kdBGfmGtEIjCUeqETaeahMKjont7+OGo= -github.com/ipld/go-trustless-utils v0.0.0/go.mod h1:rqvDGdgk2acsKiGyV5mzCZZRK8JtnEZqvUBxLuYxR6A= -github.com/ipld/ipld/specs v0.0.0-20230826120441-91918996e8eb h1:5ARxkQ9NqZq33RM7i/Eq3bvBj2RBxx2xE63hqfa+9KY= -github.com/ipld/ipld/specs v0.0.0-20230826120441-91918996e8eb/go.mod h1:AfGlAr20WOjV5PyCowEnGY3pAm5x5i+o0R8IUeir6cs= +github.com/ipld/go-trustless-utils v0.1.1-0.20230907055204-83d1e838c1c1 h1:E1YXkAnvFn0lXkiocREtp0pUBydIwMW94myLBLCvhsY= +github.com/ipld/go-trustless-utils v0.1.1-0.20230907055204-83d1e838c1c1/go.mod h1:nbUA6YuKZqNHYd3mYKALxOQa5aC8fnr2w+OxirSSOqc= +github.com/ipld/ipld/specs v0.0.0-20230907004443-0e4ff95ff474 h1:CiDtcUFyzRwhKyiS4Gn+fzdraMoNVtPHd+wVIekExPc= +github.com/ipld/ipld/specs v0.0.0-20230907004443-0e4ff95ff474/go.mod h1:WcT0DfRe+e2QFY0kcbsOnuT6jL5Q0JNZ83I5DHIdStg= github.com/ipni/go-libipni v0.3.4 h1:ZYgCE2TOZt/QJJcBZb+R63FaBLlA2suZGP2IH1fKv4A= github.com/ipni/go-libipni v0.3.4/go.mod h1:6EIUhN83pd1i6q7SCSCIuuUC3XgR7D/gjKkEnVyIQWE= github.com/ipni/index-provider v0.13.5 h1:pNOO795k4mR0bwm9npkapSWJld7fYP/8//DMJZi1w/M= diff --git a/httpipfs.go b/httpipfs.go index 7eafd92..6455850 100644 --- a/httpipfs.go +++ b/httpipfs.go @@ -116,7 +116,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) { return } - includeDupes, err := trustlesshttp.CheckFormat(req) + accept, err := trustlesshttp.CheckFormat(req) if err != nil { logError(http.StatusBadRequest, err) return @@ -154,7 +154,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) { Path: path.String(), Scope: dagScope, Bytes: byteRange, - Duplicates: includeDupes, + Duplicates: accept.Duplicates, } if fileName == "" { @@ -166,7 +166,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) { // called once we start writing blocks into the CAR (on the first Put()) res.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%q", fileName)) res.Header().Set("Cache-Control", trustlesshttp.ResponseCacheControlHeader) - res.Header().Set("Content-Type", trustlesshttp.ResponseContentTypeHeader(includeDupes)) + res.Header().Set("Content-Type", accept.String()) res.Header().Set("Etag", request.Etag()) res.Header().Set("X-Content-Type-Options", "nosniff") res.Header().Set("X-Ipfs-Path", "/"+datamodel.ParsePath(req.URL.Path).String()) diff --git a/httpipfs_test.go b/httpipfs_test.go index 0b26e2e..578990d 100644 --- a/httpipfs_test.go +++ b/httpipfs_test.go @@ -41,21 +41,21 @@ func TestHttpIpfsHandler(t *testing.T) { { name: "bad cid", path: "/ipfs/foobarbaz", - accept: trustlesshttp.RequestAcceptHeader(true), + accept: trustlesshttp.DefaultContentType().String(), expectedStatusCode: http.StatusBadRequest, expectedBody: "failed to parse CID path parameter", }, { name: "bad dag-scope", path: "/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?dag-scope=bork", - accept: trustlesshttp.RequestAcceptHeader(true), + accept: trustlesshttp.DefaultContentType().String(), expectedStatusCode: http.StatusBadRequest, expectedBody: "invalid dag-scope parameter", }, { name: "bad entity-bytes", path: "/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?entity-bytes=bork", - accept: trustlesshttp.RequestAcceptHeader(true), + accept: trustlesshttp.DefaultContentType().String(), expectedStatusCode: http.StatusBadRequest, expectedBody: "invalid entity-bytes parameter", }, @@ -73,7 +73,7 @@ func TestHttpIpfsHandler(t *testing.T) { // at least loaded the first block. name: "block not found", path: "/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi", - accept: trustlesshttp.RequestAcceptHeader(true), + accept: trustlesshttp.DefaultContentType().String(), expectedStatusCode: http.StatusInternalServerError, expectedBody: "failed to load root node: failed to load root CID: ipld: could not find bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi", }, @@ -98,7 +98,7 @@ func TestHttpIpfsHandler(t *testing.T) { func TestIntegration_Unixfs20mVariety(t *testing.T) { req := require.New(t) - testCases, err := trustlesspathing.Unixfs20mVarietyCases() + testCases, _, err := trustlesspathing.Unixfs20mVarietyCases() req.NoError(err) storage, closer, err := trustlesspathing.Unixfs20mVarietyReadableStorage() req.NoError(err) @@ -121,11 +121,11 @@ func TestIntegration_Unixfs20mVariety(t *testing.T) { request, err := http.NewRequest(http.MethodGet, testServer.URL+tc.AsQuery(), nil) req.NoError(err) - request.Header.Set("Accept", trustlesshttp.RequestAcceptHeader(false)) + request.Header.Set("Accept", trustlesshttp.DefaultContentType().WithDuplicates(false).String()) res, err := http.DefaultClient.Do(request) req.NoError(err) req.Equal(http.StatusOK, res.StatusCode) - req.Equal(trustlesshttp.ResponseContentTypeHeader(false), res.Header.Get("Content-Type")) + req.Equal(trustlesshttp.DefaultContentType().WithDuplicates(false).String(), res.Header.Get("Content-Type")) carReader, err := car.NewBlockReader(res.Body) req.NoError(err)