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

Fix/bytes api content type #4915

Merged
merged 2 commits into from
Nov 28, 2024
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
18 changes: 17 additions & 1 deletion openapi/Swarm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,23 @@ paths:
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActHistoryAddress"
responses:
"200":
description: Chunk exists
description: The chunk exists.
headers:
Content-Type:
description: The MIME type of the resource (e.g., application/octet-stream).
schema:
type: string
example: application/octet-stream
Content-Length:
description: The size of the chunk in bytes.
schema:
type: integer
example: 1024
Access-Control-Expose-Headers:
description: Headers exposed for CORS.
schema:
type: string
example: Accept-Ranges, Content-Encoding
"400":
$ref: "SwarmCommon.yaml#/components/responses/400"
"404":
Expand Down
7 changes: 3 additions & 4 deletions pkg/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *Service) bytesHeadHandler(w http.ResponseWriter, r *http.Request) {
Address swarm.Address `map:"address,resolve" validate:"required"`
}{}
if response := s.mapStructure(mux.Vars(r), &paths); response != nil {
response("invalid path params", logger, w)
w.WriteHeader(http.StatusBadRequest)
return
}

Expand All @@ -202,22 +202,21 @@ func (s *Service) bytesHeadHandler(w http.ResponseWriter, r *http.Request) {
}

getter := s.storer.Download(true)

ch, err := getter.Get(r.Context(), address)
if err != nil {
logger.Debug("get root chunk failed", "chunk_address", address, "error", err)
logger.Error(nil, "get rook chunk failed")
logger.Error(nil, "get root chunk failed")
w.WriteHeader(http.StatusNotFound)
return
}

w.Header().Add("Access-Control-Expose-Headers", "Accept-Ranges, Content-Encoding")
w.Header().Add(ContentTypeHeader, "application/octet-stream")
var span int64

if cac.Valid(ch) {
span = int64(binary.LittleEndian.Uint64(ch.Data()[:swarm.SpanSize]))
} else {
// soc
span = int64(len(ch.Data()))
}
w.Header().Set(ContentLengthHeader, strconv.FormatInt(span, 10))
Expand Down
Loading