From 5b335eaf337e2602c22bea9ed1a4a37fb6b442b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tr=C3=B3n?= Date: Fri, 9 Feb 2024 12:03:42 +0100 Subject: [PATCH] fix(api): lookahead buffer size header (#4575) --- pkg/api/api.go | 2 +- pkg/api/bzz.go | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 64c5712edf8..7d6ee42e175 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -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, ", ") diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index 6d96b3e83bc..2cf1d66d53d 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -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 { @@ -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)