Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Do not parse empty HTTP payload #175

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions electrumx/server/http_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ def __init__(self, session_mgr, db, mempool, peer_mgr, kind):
self.MAX_CHUNK_SIZE = 2016
self.hashX_subs = {}

async def format_params(self, request):
async def format_params(self, request: web.Request):
params: list
if request.method == "GET":
params = json.loads(request.query.get("params", "[]"))
else:
elif request.content_length:
json_data = await request.json()
params = json_data.get("params", [])
else:
params = []
return dict(zip(range(len(params)), params))

async def get_rpc_server(self):
Expand Down Expand Up @@ -860,11 +863,8 @@ async def transaction_broadcast(self, request):
# verified
async def scripthash_get_history(self, request):
'''Return the confirmed and unconfirmed history of a scripthash.'''
try:
params = await self.format_params(request)
scripthash = params.get(0, "")
except Exception as e:
scripthash = request
params = await self.format_params(request)
scripthash = params.get(0)

hashX = scripthash_to_hashX(scripthash)
return await self.confirmed_and_unconfirmed_history(hashX)
Expand Down
Loading