Skip to content

Commit

Permalink
Try to adjust the content length header
Browse files Browse the repository at this point in the history
  • Loading branch information
2-towns committed Oct 24, 2024
1 parent a2a76e0 commit 29ab42e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion codex/rest/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ proc retrieveCid(
if manifest.filename.isSome:
resp.setHeader("Content-Disposition", "attachment; filename=\"" & manifest.filename.get() & "\"")

resp.setHeader("Content-Length", $manifest.datasetSize.int)

await resp.prepareChunked()

Expand All @@ -117,6 +116,9 @@ proc retrieveCid(
break

bytes += buff.len

resp.setHeader("Content-Length", bytes)

await resp.sendChunk(addr buff[0], buff.len)
await resp.finish()
codex_api_downloads.inc()
Expand Down Expand Up @@ -590,14 +592,21 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
## tolerance - allowed number of nodes that can be lost before content is lost
## colateral - requested collateral from hosts when they fill slot
try:
echo "without contracts"
without contracts =? node.contracts.client:
return RestApiResponse.error(Http503, "Persistence is not enabled", headers = headers)

echo "without cid"

without cid =? cid.tryGet.catch, error:
return RestApiResponse.error(Http400, error.msg, headers = headers)

echo "body"

let body = await request.getBody()

echo "without params"

without params =? StorageRequestParams.fromJson(body), error:
return RestApiResponse.error(Http400, error.msg, headers = headers)

Expand All @@ -624,6 +633,8 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
if expiry <= 0 or expiry >= params.duration:
return RestApiResponse.error(Http400, "Expiry needs value bigger then zero and smaller then the request's duration", headers = headers)

echo "request storage"

without purchaseId =? await node.requestStorage(
cid,
params.duration,
Expand Down

0 comments on commit 29ab42e

Please sign in to comment.