@@ -41,7 +41,9 @@ type FindProvidersAsyncResponse struct {
41
41
}
42
42
43
43
type ContentRouter interface {
44
- FindProviders (ctx context.Context , key cid.Cid ) (iter.ResultIter [types.ProviderResponse ], error )
44
+ // FindProviders searches for peers who are able to provide a given key. Stream
45
+ // indicates whether or not this request will be responded as a stream.
46
+ FindProviders (ctx context.Context , key cid.Cid , stream bool ) (iter.ResultIter [types.ProviderResponse ], error )
45
47
ProvideBitswap (ctx context.Context , req * BitswapWriteProvideRequest ) (time.Duration , error )
46
48
Provide (ctx context.Context , req * WriteProvideRequest ) (types.ProviderResponse , error )
47
49
}
@@ -170,9 +172,11 @@ func (s *server) findProviders(w http.ResponseWriter, httpReq *http.Request) {
170
172
171
173
var supportsNDJSON bool
172
174
var supportsJSON bool
175
+ var streaming bool
173
176
acceptHeaders := httpReq .Header .Values ("Accept" )
174
177
if len (acceptHeaders ) == 0 {
175
178
handlerFunc = s .findProvidersJSON
179
+ streaming = false
176
180
} else {
177
181
for _ , acceptHeader := range acceptHeaders {
178
182
for _ , accept := range strings .Split (acceptHeader , "," ) {
@@ -193,15 +197,17 @@ func (s *server) findProviders(w http.ResponseWriter, httpReq *http.Request) {
193
197
194
198
if supportsNDJSON && ! s .disableNDJSON {
195
199
handlerFunc = s .findProvidersNDJSON
200
+ streaming = true
196
201
} else if supportsJSON {
197
202
handlerFunc = s .findProvidersJSON
203
+ streaming = false
198
204
} else {
199
205
writeErr (w , "FindProviders" , http .StatusBadRequest , errors .New ("no supported content types" ))
200
206
return
201
207
}
202
208
}
203
209
204
- provIter , err := s .svc .FindProviders (httpReq .Context (), cid )
210
+ provIter , err := s .svc .FindProviders (httpReq .Context (), cid , streaming )
205
211
if err != nil {
206
212
writeErr (w , "FindProviders" , http .StatusInternalServerError , fmt .Errorf ("delegate error: %w" , err ))
207
213
return
0 commit comments