diff --git a/beacon_chain/rpc/rest_nimbus_api.nim b/beacon_chain/rpc/rest_nimbus_api.nim index 592dc480d..856f59224 100644 --- a/beacon_chain/rpc/rest_nimbus_api.nim +++ b/beacon_chain/rpc/rest_nimbus_api.nim @@ -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: diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 61c763d82..b01269804 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -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: diff --git a/vendor/nim-chronos b/vendor/nim-chronos index 2a19e4ca4..939195626 160000 --- a/vendor/nim-chronos +++ b/vendor/nim-chronos @@ -1 +1 @@ -Subproject commit 2a19e4ca4c938457205a71adc2cb77f5830c58eb +Subproject commit 939195626f371048622936e50bf1b1c18979653d diff --git a/vendor/nim-http-utils b/vendor/nim-http-utils index 40048e8b3..e88e231df 160000 --- a/vendor/nim-http-utils +++ b/vendor/nim-http-utils @@ -1 +1 @@ -Subproject commit 40048e8b3e69284bdb5d4daa0a16ad93402c55db +Subproject commit e88e231dfcef4585fe3b2fbd9b664dbd28a88040 diff --git a/vendor/nim-presto b/vendor/nim-presto index ec92aab10..b3dc03be6 160000 --- a/vendor/nim-presto +++ b/vendor/nim-presto @@ -1 +1 @@ -Subproject commit ec92aab10259ff2e7bd29d682b1b68c901219bb9 +Subproject commit b3dc03be6e39c5cf2eb52a7778828a36c39fc27c