diff --git a/openapi/Swarm.yaml b/openapi/Swarm.yaml index 8be3e66bc41..48f9a6c6d3c 100644 --- a/openapi/Swarm.yaml +++ b/openapi/Swarm.yaml @@ -1066,6 +1066,11 @@ paths: $ref: "SwarmCommon.yaml#/components/schemas/SwarmReference" required: true description: Swarm address of chunk + - in: header + schema: + $ref: "SwarmCommon.yaml#/components/parameters/SwarmCache" + name: swarm-cache + required: false responses: "200": description: Retrieved chunk content diff --git a/pkg/api/chunk.go b/pkg/api/chunk.go index 910270abf8a..25e1d6c65ed 100644 --- a/pkg/api/chunk.go +++ b/pkg/api/chunk.go @@ -150,6 +150,18 @@ func (s *Service) chunkGetHandler(w http.ResponseWriter, r *http.Request) { logger := s.logger.WithName("get_chunk_by_address").Build() loggerV1 := logger.V(1).Build() + headers := struct { + Cache *bool `map:"Swarm-Cache"` + }{} + if response := s.mapStructure(r.Header, &headers); response != nil { + response("invalid header params", logger, w) + return + } + cache := true + if headers.Cache != nil { + cache = *headers.Cache + } + paths := struct { Address swarm.Address `map:"address,resolve" validate:"required"` }{} @@ -158,7 +170,7 @@ func (s *Service) chunkGetHandler(w http.ResponseWriter, r *http.Request) { return } - chunk, err := s.storer.Download(true).Get(r.Context(), paths.Address) + chunk, err := s.storer.Download(cache).Get(r.Context(), paths.Address) if err != nil { if errors.Is(err, storage.ErrNotFound) { loggerV1.Debug("chunk not found", "address", paths.Address)