1- # Created by ChatGPT (GPT-3.5)
1+ # Created with the help of the ChatGPT (GPT-3.5)
22# REF: https://chat.openai.com/share/4ab741e7-8059-4be1-b3da-46b8e78d98cc
33# REF: https://gealber.com/gzip-middleware-fastapi
44import gzip
5- import json
65from starlette .types import Message
76from starlette .requests import Request
87from starlette .responses import JSONResponse
@@ -15,7 +14,7 @@ async def set_body(self, request: Request):
1514 content_encoding = request .headers .get ('Content-Encoding' , '' ).lower ()
1615 print ("content_encoding" , content_encoding )
1716 if 'gzip' in content_encoding :
18- print ("receive_" , receive_ )
17+ # print("receive_", receive_)
1918
2019 try :
2120 content_length = int (
@@ -27,12 +26,10 @@ async def set_body(self, request: Request):
2726 status_code = 400 ,
2827 )
2928 json_byte_string = gzip .decompress (body )
30- # json_string = json_byte_string.decode('utf-8')
31- # json_object = json.dumps(json_string)
3229 receive_ ['body' ] = json_byte_string
3330 print ("content_length" , content_length )
34- print ("body" , body )
35- print ("receive_[' body'] " , receive_ ['body' ])
31+ # print("body", body)
32+ print ("gzip decompressed body: " , receive_ ['body' ])
3633 except ValueError :
3734 return JSONResponse (
3835 content = {"error" : "Invalid Content-Length header" },
0 commit comments