Skip to content

Commit

Permalink
fix(api): lookahead buffer size header (#4575)
Browse files Browse the repository at this point in the history
  • Loading branch information
zelig authored Feb 9, 2024
1 parent 0ece898 commit 5b335ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (s *Service) corsHandler(h http.Handler) http.Handler {
allowedHeaders := []string{
"User-Agent", "Accept", "X-Requested-With", "Access-Control-Request-Headers", "Access-Control-Request-Method", "Accept-Ranges", "Content-Encoding",
AuthorizationHeader, AcceptEncodingHeader, ContentTypeHeader, ContentDispositionHeader, RangeHeader, OriginHeader,
SwarmTagHeader, SwarmPinHeader, SwarmEncryptHeader, SwarmIndexDocumentHeader, SwarmErrorDocumentHeader, SwarmCollectionHeader, SwarmPostageBatchIdHeader, SwarmDeferredUploadHeader, SwarmRedundancyLevelHeader, SwarmRedundancyStrategyHeader, SwarmRedundancyFallbackModeHeader, SwarmChunkRetrievalTimeoutHeader, SwarmFeedIndexHeader, SwarmFeedIndexNextHeader, GasPriceHeader, GasLimitHeader, ImmutableHeader,
SwarmTagHeader, SwarmPinHeader, SwarmEncryptHeader, SwarmIndexDocumentHeader, SwarmErrorDocumentHeader, SwarmCollectionHeader, SwarmPostageBatchIdHeader, SwarmDeferredUploadHeader, SwarmRedundancyLevelHeader, SwarmRedundancyStrategyHeader, SwarmRedundancyFallbackModeHeader, SwarmChunkRetrievalTimeoutHeader, SwarmLookAheadBufferSizeHeader, SwarmFeedIndexHeader, SwarmFeedIndexNextHeader, GasPriceHeader, GasLimitHeader, ImmutableHeader,
}
allowedHeadersStr := strings.Join(allowedHeaders, ", ")

Expand Down
12 changes: 4 additions & 8 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h
Strategy getter.Strategy `map:"Swarm-Redundancy-Strategy"`
FallbackMode bool `map:"Swarm-Redundancy-Fallback-Mode"`
ChunkRetrievalTimeout string `map:"Swarm-Chunk-Retrieval-Timeout"`
LookaheadBufferSize *string `map:"Swarm-Lookahead-Buffer-Size"`
LookaheadBufferSize *int `map:"Swarm-Lookahead-Buffer-Size"`
}{}

if response := s.mapStructure(r.Header, &headers); response != nil {
Expand Down Expand Up @@ -537,16 +537,12 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h
}
w.Header().Set(ContentLengthHeader, strconv.FormatInt(l, 10))
w.Header().Set("Access-Control-Expose-Headers", ContentDispositionHeader)
bufSize := int64(lookaheadBufferSize(l))
bufSize := lookaheadBufferSize(l)
if headers.LookaheadBufferSize != nil {
bufSize, err = strconv.ParseInt(*headers.LookaheadBufferSize, 10, 64)
if err != nil {
logger.Debug("parsing lookahead buffer size", "error", err)
bufSize = 0
}
bufSize = *(headers.LookaheadBufferSize)
}
if bufSize > 0 {
http.ServeContent(w, r, "", time.Now(), langos.NewBufferedLangos(reader, int(bufSize)))
http.ServeContent(w, r, "", time.Now(), langos.NewBufferedLangos(reader, bufSize))
return
}
http.ServeContent(w, r, "", time.Now(), reader)
Expand Down

0 comments on commit 5b335ea

Please sign in to comment.