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

View File

@ -68,6 +68,10 @@ const
AltairVersion =
[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
EmptyBody* = object
@ -2317,7 +2321,7 @@ proc parseRoot(value: string): Result[Eth2Digest, cstring] =
proc decodeBody*[T](t: typedesc[T],
body: ContentBody): Result[T, cstring] =
if body.contentType != "application/json":
if body.contentType != ApplicationJsonMediaType:
return err("Unsupported content type")
let data =
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