httpserver.nim: adding 'Content-Type: application/json' header to the response (#165)

This commit is contained in:
Ivan Folgueira Bande 2023-06-15 11:11:26 +02:00 committed by GitHub
parent 4c31a8bd46
commit 0bf2bcbe74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,14 +41,19 @@ proc processClientRpc(rpcServer: RpcHttpServer): HttpProcessCallback =
let body = await request.getBody()
let headers = HttpTable.init([("Content-Type",
"application/json; charset=utf-8")])
let future = rpcServer.route(string.fromBytes(body))
yield future
if future.failed:
debug "Internal error while processing JSON-RPC call"
return await request.respond(Http503, "Internal error while processing JSON-RPC call")
return await request.respond(Http503,
"Internal error while processing JSON-RPC call",
headers)
else:
var data = future.read()
let res = await request.respond(Http200, data)
let res = await request.respond(Http200, data, headers)
trace "JSON-RPC result has been sent"
return res
else: