Last active
May 13, 2021 20:28
-
-
Save daviddavis/34e1b4be12987b05cd0d4990989d2159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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