add `sszResponsePlain` for pre-encoded SSZ data (#4171)
For pre-encoded JSON REST responses we have `jsonResponsePlain`. Adds a `sszResponsePlain` function to serve similar purpose for SSZ. This avoids caller having to explicitly specify Http200 and media type.
This commit is contained in:
parent
6425f3f856
commit
77ea188c92
|
@ -820,7 +820,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
if not node.dag.getBlockSSZ(bid, data):
|
if not node.dag.getBlockSSZ(bid, data):
|
||||||
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
||||||
|
|
||||||
RestApiResponse.response(data, Http200, $sszMediaType)
|
RestApiResponse.sszResponsePlain(data)
|
||||||
elif contentType == jsonMediaType:
|
elif contentType == jsonMediaType:
|
||||||
let bdata = node.dag.getForkedBlock(bid).valueOr:
|
let bdata = node.dag.getForkedBlock(bid).valueOr:
|
||||||
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
||||||
|
@ -862,8 +862,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
fork = node.dag.cfg.blockForkAtEpoch(bid.slot.epoch)
|
fork = node.dag.cfg.blockForkAtEpoch(bid.slot.epoch)
|
||||||
headers = [("eth-consensus-version", fork.toString())]
|
headers = [("eth-consensus-version", fork.toString())]
|
||||||
|
|
||||||
RestApiResponse.response(data, Http200, $sszMediaType,
|
RestApiResponse.sszResponsePlain(data, headers)
|
||||||
headers = headers)
|
|
||||||
elif contentType == jsonMediaType:
|
elif contentType == jsonMediaType:
|
||||||
let bdata = node.dag.getForkedBlock(bid).valueOr:
|
let bdata = node.dag.getForkedBlock(bid).valueOr:
|
||||||
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
||||||
|
|
|
@ -454,8 +454,14 @@ proc jsonErrorList*(t: typedesc[RestApiResponse],
|
||||||
default
|
default
|
||||||
RestApiResponse.error(status, data, "application/json")
|
RestApiResponse.error(status, data, "application/json")
|
||||||
|
|
||||||
|
proc sszResponsePlain*(t: typedesc[RestApiResponse], res: seq[byte],
|
||||||
|
headers: openArray[RestKeyValueTuple] = []
|
||||||
|
): RestApiResponse =
|
||||||
|
RestApiResponse.response(res, Http200, "application/octet-stream",
|
||||||
|
headers = headers)
|
||||||
|
|
||||||
proc sszResponse*(t: typedesc[RestApiResponse], data: auto,
|
proc sszResponse*(t: typedesc[RestApiResponse], data: auto,
|
||||||
headers: openArray[tuple[key: string, value: string]]
|
headers: openArray[RestKeyValueTuple] = []
|
||||||
): RestApiResponse =
|
): RestApiResponse =
|
||||||
let res =
|
let res =
|
||||||
block:
|
block:
|
||||||
|
|
Loading…
Reference in New Issue