This commit is contained in:
Eugene Kabanov 2022-08-06 14:55:40 +03:00 committed by GitHub
parent 8273b3d909
commit fe5435ed96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 16 deletions

View File

@ -169,7 +169,8 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
if contentBody.isNone: if contentBody.isNone:
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError) return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
template setGraffitiAux(node: BeaconNode, graffitiStr: string): RestApiResponse = template setGraffitiAux(node: BeaconNode,
graffitiStr: string): RestApiResponse =
node.graffitiBytes = try: node.graffitiBytes = try:
GraffitiBytes.init(graffitiStr) GraffitiBytes.init(graffitiStr)
except CatchableError as err: except CatchableError as err:
@ -177,21 +178,21 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
err.msg) err.msg)
RestApiResponse.jsonResponse((result: true)) RestApiResponse.jsonResponse((result: true))
case contentBody.get.contentType let body = contentBody.get()
of "application/json": if body.contentType == ApplicationJsonMediaType:
let graffitiBytes = decodeBody(GraffitiBytes, contentBody.get) let graffitiBytes = decodeBody(GraffitiBytes, body)
if graffitiBytes.isErr: if graffitiBytes.isErr():
return RestApiResponse.jsonError(Http400, InvalidGraffitiBytesValue, return RestApiResponse.jsonError(Http400, InvalidGraffitiBytesValue,
$graffitiBytes.error) $graffitiBytes.error())
node.graffitiBytes = graffitiBytes.get node.graffitiBytes = graffitiBytes.get()
return RestApiResponse.jsonResponse((result: true)) return RestApiResponse.jsonResponse((result: true))
of "text/plain": elif body.contentType == TextPlainMediaType:
return node.setGraffitiAux contentBody.get.strData return node.setGraffitiAux body.strData()
of "application/x-www-form-urlencoded": elif body.contentType == UrlEncodedMediaType:
return node.setGraffitiAux decodeUrl(contentBody.get.strData) return node.setGraffitiAux decodeUrl(body.strData())
else: else:
return RestApiResponse.jsonError(Http400, "Unsupported content type: " & return RestApiResponse.jsonError(Http400, "Unsupported content type: " &
$contentBody.get.contentType) $body.contentType)
router.api(MethodGet, "/nimbus/v1/graffiti") do ( router.api(MethodGet, "/nimbus/v1/graffiti") do (
) -> RestApiResponse: ) -> RestApiResponse:

View File

@ -68,6 +68,10 @@ const
AltairVersion = AltairVersion =
[byte('a'), byte('l'), byte('t'), byte('a'), byte('i'), byte('r')] [byte('a'), byte('l'), byte('t'), byte('a'), byte('i'), byte('r')]
ApplicationJsonMediaType* = MediaType.init("application/json")
TextPlainMediaType* = MediaType.init("text/plain")
UrlEncodedMediaType* = MediaType.init("application/x-www-form-urlencoded")
type type
EmptyBody* = object EmptyBody* = object
@ -2317,7 +2321,7 @@ proc parseRoot(value: string): Result[Eth2Digest, cstring] =
proc decodeBody*[T](t: typedesc[T], proc decodeBody*[T](t: typedesc[T],
body: ContentBody): Result[T, cstring] = body: ContentBody): Result[T, cstring] =
if body.contentType != "application/json": if body.contentType != ApplicationJsonMediaType:
return err("Unsupported content type") return err("Unsupported content type")
let data = let data =
try: try:

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 2a19e4ca4c938457205a71adc2cb77f5830c58eb Subproject commit 939195626f371048622936e50bf1b1c18979653d

@ -1 +1 @@
Subproject commit 40048e8b3e69284bdb5d4daa0a16ad93402c55db Subproject commit e88e231dfcef4585fe3b2fbd9b664dbd28a88040

2
vendor/nim-presto vendored

@ -1 +1 @@
Subproject commit ec92aab10259ff2e7bd29d682b1b68c901219bb9 Subproject commit b3dc03be6e39c5cf2eb52a7778828a36c39fc27c