Skip to content

Commit

Permalink
feat: support entity-bytes requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 30, 2023
1 parent c24c4c3 commit faf175c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ go 1.20
require (
github.com/dustin/go-humanize v1.0.1
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc7
github.com/filecoin-project/lassie v0.12.2-0.20230614045620-19b6e938241c
github.com/filecoin-project/lassie v0.13.1-0.20230630054437-c777369112ca
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs/go-block-format v0.1.2
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-graphsync v0.14.6
github.com/ipfs/go-ipld-format v0.5.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipfs/go-unixfsnode v1.7.1
github.com/ipfs/go-unixfsnode v1.7.2-0.20230622024455-de5cbf74cbe0
github.com/ipld/go-car/v2 v2.10.1
github.com/ipld/go-codec-dagpb v1.6.0
github.com/ipld/go-ipld-prime v0.20.1-0.20230613110822-3142e1304e55
github.com/ipld/go-ipld-prime v0.20.1-0.20230629094729-829a31766846
github.com/ipni/go-libipni v0.2.3
github.com/ipni/index-provider v0.13.3
github.com/libp2p/go-libp2p v0.28.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNdofHZoGPjfNaAo5Q=
github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo=
github.com/filecoin-project/lassie v0.12.2-0.20230614045620-19b6e938241c h1:2E1hw30L6zKaHsNnqoqXc48A3EDJ/afnGMPFna8c4h0=
github.com/filecoin-project/lassie v0.12.2-0.20230614045620-19b6e938241c/go.mod h1:kbO6Ljk/2ug6CLJuHsgsd4c6EVrAmnVQKFAktmETSI4=
github.com/filecoin-project/lassie v0.13.1-0.20230630054437-c777369112ca h1:tcX9PdSBOYnglhmKXX7x14oRbM7D03uqrng9jWH58Uw=
github.com/filecoin-project/lassie v0.13.1-0.20230630054437-c777369112ca/go.mod h1:3mk5M7G3lqs+Fayufyveys5AXmcee+6mQaZ/MvXRabM=
github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
Expand Down Expand Up @@ -313,17 +313,17 @@ github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j
github.com/ipfs/go-peertaskqueue v0.8.1 h1:YhxAs1+wxb5jk7RvS0LHdyiILpNmRIRnZVztekOF0pg=
github.com/ipfs/go-peertaskqueue v0.8.1/go.mod h1:Oxxd3eaK279FxeydSPPVGHzbwVeHjatZ2GA8XD+KbPU=
github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU=
github.com/ipfs/go-unixfsnode v1.7.1 h1:RRxO2b6CSr5UQ/kxnGzaChTjp5LWTdf3Y4n8ANZgB/s=
github.com/ipfs/go-unixfsnode v1.7.1/go.mod h1:PVfoyZkX1B34qzT3vJO4nsLUpRCyhnMuHBznRcXirlk=
github.com/ipfs/go-unixfsnode v1.7.2-0.20230622024455-de5cbf74cbe0 h1:XTKKTDz0rbJ53ff/7borHTvN64zJK74wZDvrYfdN0Fg=
github.com/ipfs/go-unixfsnode v1.7.2-0.20230622024455-de5cbf74cbe0/go.mod h1:PVfoyZkX1B34qzT3vJO4nsLUpRCyhnMuHBznRcXirlk=
github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs=
github.com/ipld/go-car/v2 v2.10.1 h1:MRDqkONNW9WRhB79u+Z3U5b+NoN7lYA5B8n8qI3+BoI=
github.com/ipld/go-car/v2 v2.10.1/go.mod h1:sQEkXVM3csejlb1kCCb+vQ/pWBKX9QtvsrysMQjOgOg=
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=
github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0/go.mod h1:odxGcpiQZLzP5+yGu84Ljo8y3EzCvNAQKEodHNsHLXA=
github.com/ipld/go-ipld-prime v0.20.1-0.20230613110822-3142e1304e55 h1:D1JUX6l0+ugD3PE99l/NmN/97jz9YNP0uZZRLAGZQhs=
github.com/ipld/go-ipld-prime v0.20.1-0.20230613110822-3142e1304e55/go.mod h1:PRQpXNcJypaPiiSdarsrJABPkYrBvafwDl0B9HjujZ8=
github.com/ipld/go-ipld-prime v0.20.1-0.20230629094729-829a31766846 h1:0gIWxUu4gU/Do25cwk82TRA621GjoZRSyVY472LaBrQ=
github.com/ipld/go-ipld-prime v0.20.1-0.20230629094729-829a31766846/go.mod h1:PRQpXNcJypaPiiSdarsrJABPkYrBvafwDl0B9HjujZ8=
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo=
github.com/ipni/go-libipni v0.2.3 h1:uuRbHzrt/abYOlkZXSSMqOzekBgPzsY5W3eLf2v/TMQ=
github.com/ipni/go-libipni v0.2.3/go.mod h1:jJd9baZTFVfiLz9H3+qM39NLpUu88VlgdSQZ9sbYrv0=
Expand Down
14 changes: 10 additions & 4 deletions httpipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
lassiehttp "github.com/filecoin-project/lassie/pkg/server/http"
lassietypes "github.com/filecoin-project/lassie/pkg/types"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-unixfsnode"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/linking"
)
Expand Down Expand Up @@ -113,11 +112,17 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
return
}

byteRange, err := lassiehttp.ParseByteRange(req)
if err != nil {
logError(http.StatusBadRequest, err)
return
}

if fileName == "" {
fileName = fmt.Sprintf("%s%s", rootCid.String(), lassiehttp.FilenameExtCar)
}

selNode := unixfsnode.UnixFSPathSelectorBuilder(path.String(), dagScope.TerminalSelectorSpec(), false)
selNode := lassietypes.PathScopeSelector(path.String(), dagScope, byteRange)

bytesWrittenCh := make(chan struct{})
writer := newIpfsResponseWriter(res, hi.maxResponseBytes, func() {
Expand All @@ -126,7 +131,7 @@ func (hi *HttpIpfs) ServeHTTP(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Accept-Ranges", lassiehttp.ResponseAcceptRangesHeader)
res.Header().Set("Cache-Control", lassiehttp.ResponseCacheControlHeader)
res.Header().Set("Content-Type", lassiehttp.ResponseContentTypeHeader)
res.Header().Set("Etag", etag(rootCid, path.String(), dagScope, includeDupes))
res.Header().Set("Etag", etag(rootCid, path.String(), dagScope, byteRange, includeDupes))
res.Header().Set("X-Content-Type-Options", "nosniff")
res.Header().Set("X-Ipfs-Path", "/"+datamodel.ParsePath(req.URL.Path).String())
close(bytesWrittenCh)
Expand Down Expand Up @@ -174,11 +179,12 @@ func (w *ipfsResponseWriter) Write(p []byte) (int, error) {
return w.w.Write(p)
}

func etag(root cid.Cid, path string, scope lassietypes.DagScope, duplicates bool) string {
func etag(root cid.Cid, path string, scope lassietypes.DagScope, bytes *lassietypes.ByteRange, duplicates bool) string {
return lassietypes.RetrievalRequest{
Cid: root,
Path: path,
Scope: scope,
Bytes: bytes,
Duplicates: duplicates,
}.Etag()
}
Expand Down

0 comments on commit faf175c

Please sign in to comment.