Skip to content

Commit a2a059f

Browse files
committed
♻️ shorter
1 parent dc8922b commit a2a059f

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

nonebot_plugin_all4one/onebotimpl/__init__.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,11 @@ async def _handle_http(
260260
return response
261261
try:
262262
if request.content:
263-
if request.headers.get("Content-Type") == "application/msgpack":
263+
if (
264+
content_type := request.headers.get("Content-Type")
265+
) == "application/msgpack":
264266
data = msgpack.unpackb(request.content)
265-
elif request.headers.get("Content-Type") == "application/json":
267+
elif content_type == "application/json":
266268
data = json.loads(request.content)
267269
else:
268270
return Response(415, content="Invalid Content-Type")
@@ -274,18 +276,11 @@ async def _handle_http(
274276
)
275277
if "echo" in data:
276278
resp["echo"] = data["echo"]
277-
if request.headers.get("Content-Type") == "application/json":
278-
return Response(
279-
200,
280-
headers={"Content-Type": "application/json"},
281-
content=encode_data(resp, False),
282-
)
283-
else:
284-
return Response(
285-
200,
286-
headers={"Content-Type": "application/msgpack"},
287-
content=encode_data(resp, True),
288-
)
279+
return Response(
280+
200,
281+
headers={"Content-Type": content_type},
282+
content=encode_data(resp, content_type != "application/json"),
283+
)
289284
except Exception as e:
290285
logger.debug(e)
291286
return Response(204)

0 commit comments

Comments
 (0)