Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added swarm-cache header to chunks get handler #4486

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openapi/Swarm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion pkg/api/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}{}
Expand All @@ -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)
Expand Down
Loading