Skip to content

Commit

Permalink
plugin/clnrest: do not read json payload if data length is zero
Browse files Browse the repository at this point in the history
OpenAPI readme always includes `content-type: application/json` header, even when body parameters are empty.
But the server expects data if the content-type has been sent.
This results in a "Server Error" response for non-param requests from readme doc.
This only affects readme requests as it is designed to send the header by default.

Changelog-None
  • Loading branch information
ShahanaFarooqui authored and rustyrussell committed Aug 31, 2023
1 parent f4f4ab3 commit e788f76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion plugins/clnrest/utilities/rpc_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def post(self, rpc_method):

try:
if request.is_json:
payload = request.get_json()
if len(request.data) != 0:
payload = request.get_json()
else:
payload = {}
else:
payload = request.form.to_dict()
return call_rpc_method(plugin, rpc_method, payload), 201
Expand Down
5 changes: 4 additions & 1 deletion plugins/clnrest/utilities/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def verify_rune(plugin, request):
raise Exception('{ "error": {"code": 403, "message": "Not authorized: Missing rune"} }')

if request.is_json:
rpc_params = request.get_json()
if len(request.data) != 0:
rpc_params = request.get_json()
else:
rpc_params = {}
else:
rpc_params = request.form.to_dict()

Expand Down

0 comments on commit e788f76

Please sign in to comment.