Put `application/json` as a higher preference than `application/octet-stream`
This commit is contained in:
parent
29e2169585
commit
0051af430b
|
@ -806,18 +806,17 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
|
||||
let contentType =
|
||||
block:
|
||||
let res = preferredContentType("application/octet-stream",
|
||||
"application/json")
|
||||
let res = preferredContentType(jsonMediaType,
|
||||
sszMediaType)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http406, ContentNotAcceptableError)
|
||||
res.get()
|
||||
return
|
||||
case bdata.kind
|
||||
of BeaconBlockFork.Phase0:
|
||||
case contentType
|
||||
of "application/octet-stream":
|
||||
if contentType == sszMediaType:
|
||||
RestApiResponse.sszResponse(bdata.phase0Data)
|
||||
of "application/json":
|
||||
elif contentType == jsonMediaType:
|
||||
RestApiResponse.jsonResponse(bdata.phase0Data)
|
||||
else:
|
||||
RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
||||
|
@ -836,17 +835,16 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
return RestApiResponse.jsonError(Http404, BlockNotFoundError)
|
||||
let contentType =
|
||||
block:
|
||||
let res = preferredContentType("application/octet-stream",
|
||||
"application/json")
|
||||
let res = preferredContentType(jsonMediaType,
|
||||
sszMediaType)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http406, ContentNotAcceptableError)
|
||||
res.get()
|
||||
return
|
||||
case contentType
|
||||
of "application/octet-stream":
|
||||
if contentType == sszMediaType:
|
||||
withBlck(bdata):
|
||||
RestApiResponse.sszResponse(blck)
|
||||
of "application/json":
|
||||
elif contentType == jsonMediaType:
|
||||
RestApiResponse.jsonResponsePlain(bdata.asSigned())
|
||||
else:
|
||||
RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
||||
|
|
|
@ -32,8 +32,8 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
bres.get()
|
||||
let contentType =
|
||||
block:
|
||||
let res = preferredContentType("application/octet-stream",
|
||||
"application/json")
|
||||
let res = preferredContentType(jsonMediaType,
|
||||
sszMediaType)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http406, ContentNotAcceptableError)
|
||||
res.get()
|
||||
|
@ -41,13 +41,12 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
return
|
||||
case stateData.data.kind
|
||||
of BeaconStateFork.Phase0:
|
||||
case contentType
|
||||
of "application/octet-stream":
|
||||
RestApiResponse.sszResponse(stateData.data.phase0Data.data)
|
||||
of "application/json":
|
||||
RestApiResponse.jsonResponse(stateData.data.phase0Data.data)
|
||||
else:
|
||||
RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
||||
if contentType == sszMediaType:
|
||||
RestApiResponse.sszResponse(stateData.data.phase0Data.data)
|
||||
elif contentType == jsonMediaType:
|
||||
RestApiResponse.jsonResponse(stateData.data.phase0Data.data)
|
||||
else:
|
||||
RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
||||
of BeaconStateFork.Altair, BeaconStateFork.Bellatrix:
|
||||
RestApiResponse.jsonError(Http404, StateNotFoundError)
|
||||
return RestApiResponse.jsonError(Http404, StateNotFoundError)
|
||||
|
@ -68,17 +67,16 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
bres.get()
|
||||
let contentType =
|
||||
block:
|
||||
let res = preferredContentType("application/octet-stream",
|
||||
"application/json")
|
||||
let res = preferredContentType(jsonMediaType,
|
||||
sszMediaType)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http406, ContentNotAcceptableError)
|
||||
res.get()
|
||||
node.withStateForBlockSlot(bslot):
|
||||
return
|
||||
case contentType
|
||||
of "application/json":
|
||||
if contentType == jsonMediaType:
|
||||
RestApiResponse.jsonResponsePlain(stateData.data)
|
||||
of "application/octet-stream":
|
||||
elif contentType == sszMediaType:
|
||||
withState(stateData.data):
|
||||
RestApiResponse.sszResponse(state.data)
|
||||
else:
|
||||
|
|
|
@ -108,10 +108,10 @@ proc installEventApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
$res.error())
|
||||
res.get()
|
||||
|
||||
let res = preferredContentType("text/event-stream")
|
||||
let res = preferredContentType(textEventStreamMediaType)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http406, ContentNotAcceptableError)
|
||||
if res.get() != "text/event-stream":
|
||||
if res.get() != textEventStreamMediaType:
|
||||
return RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
||||
|
||||
var response = request.getResponse()
|
||||
|
|
|
@ -273,3 +273,8 @@ func keysToIndices*(cacheTable: var Table[ValidatorPubKey, ValidatorIndex],
|
|||
|
||||
proc getRouter*(): RestRouter =
|
||||
RestRouter.init(validate)
|
||||
|
||||
const
|
||||
jsonMediaType* = MediaType.init("application/json")
|
||||
sszMediaType* = MediaType.init("application/octet-stream")
|
||||
textEventStreamMediaType* = MediaType.init("text/event-stream")
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7dc58d42b6905a7fd7531875fa76060f8f744e4e
|
||||
Subproject commit 87197230779002a2bfa8642f0e2ae07e2349e304
|
|
@ -1 +1 @@
|
|||
Subproject commit 689da19e9e9cfff4ced85e2b25c6b2b5598ed079
|
||||
Subproject commit 40048e8b3e69284bdb5d4daa0a16ad93402c55db
|
|
@ -1 +1 @@
|
|||
Subproject commit fba35d5a679fdb2aef7300e05d7e52307ae9c45b
|
||||
Subproject commit 22746c5cd20522176a4a4de1d660c735087517e9
|
Loading…
Reference in New Issue