From 29ab42e107a3f75f5f5a22d13bb59bd9b30de02f Mon Sep 17 00:00:00 2001 From: Arnaud Date: Thu, 24 Oct 2024 11:52:00 +0200 Subject: [PATCH] Try to adjust the content length header --- codex/rest/api.nim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 73e07f88c..46f1ec5e7 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -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() @@ -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() @@ -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) @@ -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,