@@ -12,6 +12,7 @@ import (
1212 "github.com/storacha/go-libstoracha/blobindex"
1313 rclient "github.com/storacha/go-ucanto/client/retrieval"
1414 "github.com/storacha/go-ucanto/core/dag/blockstore"
15+ "github.com/storacha/go-ucanto/core/delegation"
1516 "github.com/storacha/go-ucanto/core/invocation"
1617 "github.com/storacha/go-ucanto/core/receipt"
1718 "github.com/storacha/go-ucanto/core/result"
@@ -30,11 +31,11 @@ func NewBlobIndexLookup(httpClient *http.Client) BlobIndexLookup {
3031}
3132
3233// Find fetches the blob index from the given fetchURL
33- func (s * simpleLookup ) Find (ctx context.Context , _ types.EncodedContextID , result model.ProviderResult , spec types.RetrievalRequest ) (blobindex.ShardedDagIndexView , error ) {
34+ func (s * simpleLookup ) Find (ctx context.Context , _ types.EncodedContextID , result model.ProviderResult , request types.RetrievalRequest ) (blobindex.ShardedDagIndexView , error ) {
3435 // If retrieval authroization details were provided, make a UCAN authorized
3536 // retrieval request.
36- if spec .Auth != nil {
37- body , err := doAuthorizedRetrieval (ctx , spec , s .httpClient )
37+ if request .Auth != nil {
38+ body , err := doAuthorizedRetrieval (ctx , s .httpClient , request )
3839 if err != nil {
3940 return nil , fmt .Errorf ("executing authorized retrieval: %w" , err )
4041 }
@@ -43,52 +44,52 @@ func (s *simpleLookup) Find(ctx context.Context, _ types.EncodedContextID, resul
4344 }
4445
4546 // attempt to fetch the index from provided url
46- req , err := http .NewRequestWithContext (ctx , http .MethodGet , spec .URL .String (), nil )
47+ httpReq , err := http .NewRequestWithContext (ctx , http .MethodGet , request .URL .String (), nil )
4748 if err != nil {
4849 return nil , fmt .Errorf ("constructing request: %w" , err )
4950 }
50- rng := spec .Range
51+ rng := request .Range
5152 if rng != nil {
5253 rangeHeader := fmt .Sprintf ("bytes=%d-" , rng .Offset )
5354 if rng .Length != nil {
5455 rangeHeader += strconv .FormatUint (rng .Offset + * rng .Length - 1 , 10 )
5556 }
56- req .Header .Set ("Range" , rangeHeader )
57+ httpReq .Header .Set ("Range" , rangeHeader )
5758 }
58- resp , err := s .httpClient .Do (req )
59+ resp , err := s .httpClient .Do (httpReq )
5960 if err != nil {
6061 return nil , fmt .Errorf ("failed to fetch index: %w" , err )
6162 }
6263 if resp .StatusCode < 200 || resp .StatusCode > 299 {
6364 body , _ := io .ReadAll (resp .Body )
64- return nil , fmt .Errorf ("failure response fetching index. status: %s, message: %s, url: %s" , resp .Status , string (body ), spec .URL .String ())
65+ return nil , fmt .Errorf ("failure response fetching index. status: %s, message: %s, url: %s" , resp .Status , string (body ), request .URL .String ())
6566 }
6667 defer resp .Body .Close ()
6768 return blobindex .Extract (resp .Body )
6869}
6970
70- func doAuthorizedRetrieval (ctx context.Context , spec types. RetrievalRequest , httpClient * http.Client ) (io.ReadCloser , error ) {
71+ func doAuthorizedRetrieval (ctx context.Context , httpClient * http.Client , request types. RetrievalRequest ) (io.ReadCloser , error ) {
7172 headers := http.Header {}
72- if spec .Range != nil {
73- if spec .Range .Length != nil {
74- headers .Set ("Range" , fmt .Sprintf ("bytes=%d-%d" , spec .Range .Offset , spec .Range .Offset + * spec .Range .Length - 1 ))
73+ if request .Range != nil {
74+ if request .Range .Length != nil {
75+ headers .Set ("Range" , fmt .Sprintf ("bytes=%d-%d" , request .Range .Offset , request .Range .Offset + * request .Range .Length - 1 ))
7576 } else {
76- headers .Set ("Range" , fmt .Sprintf ("bytes=%d-" , spec .Range .Offset ))
77+ headers .Set ("Range" , fmt .Sprintf ("bytes=%d-" , request .Range .Offset ))
7778 }
7879 }
7980
8081 conn , err := rclient .NewConnection (
81- spec .Auth .Audience ,
82- spec .URL ,
82+ request .Auth .Audience ,
83+ request .URL ,
8384 rclient .WithClient (httpClient ),
8485 rclient .WithHeaders (headers ),
8586 )
8687 if err != nil {
8788 return nil , err
8889 }
8990
90- iss , aud , cap := spec .Auth .Issuer , spec .Auth .Audience , spec .Auth .Capability
91- inv , err := invocation .Invoke (iss , aud , cap )
91+ iss , aud , cap := request .Auth .Issuer , request .Auth .Audience , request .Auth .Capability
92+ inv , err := invocation .Invoke (iss , aud , cap , delegation . WithProof ( request . Auth . Proofs ... ) )
9293 if err != nil {
9394 return nil , err
9495 }
0 commit comments