Skip to content

Instantly share code, notes, and snippets.

@daviddavis
Last active May 13, 2021 20:28
Show Gist options
  • Save daviddavis/34e1b4be12987b05cd0d4990989d2159 to your computer and use it in GitHub Desktop.
Save daviddavis/34e1b4be12987b05cd0d4990989d2159 to your computer and use it in GitHub Desktop.
import aiohttp
import asyncio
from multidict import MultiDict
async def main():
headers = MultiDict({"User-Agent": "ua1"})
headers.extend({"User-Agent": "ua2"})
async with aiohttp.ClientSession(headers=headers) as session:
async with session.get('http://localhost:8000') as response:
text = await response.text()
print("Request sent.")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
#!/usr/bin/env python3
import http.server as SimpleHTTPServer
import socketserver as SocketServer
import logging
PORT = 8000
class GetHandler(
SimpleHTTPServer.SimpleHTTPRequestHandler
):
def do_GET(self):
logging.error(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = GetHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment