Advertisement
Guest User

monkey patch aiohttp HeadersParser

a guest
Mar 17th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # Remove aiohttp header size by monkey patching HeadersParser
  2. # Solution for https://www.v2ex.com/t/762640
  3. from aiohttp.http_parser import HeadersParser
  4.  
  5.  
  6. def monkey_init(
  7.     self,
  8.     max_line_size: int = 8190,
  9.     max_headers: int = 32768,
  10.     max_field_size: int = 8190,
  11. ) -> None:
  12.     self.max_line_size = max_line_size
  13.     self.max_headers = max_headers
  14.     # self.max_field_size = max_field_size
  15.     self.max_field_size = 2 << 31
  16.  
  17.  
  18. HeadersParser.__init__ = monkey_init
  19.  
  20. import asyncio
  21. from aiohttp import ClientSession
  22.  
  23.  
  24. async def main():
  25.     async with ClientSession() as req:
  26.         async with req.get("http://127.0.0.1:8080/") as r:
  27.             print(await r.text())
  28.  
  29.  
  30. asyncio.run(main())
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement