Skip to content

Instantly share code, notes, and snippets.

@NicolaiSoeborg
Created December 28, 2023 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicolaiSoeborg/a75e2a474c315ac1cb2e79de1f594d8c to your computer and use it in GitHub Desktop.
Save NicolaiSoeborg/a75e2a474c315ac1cb2e79de1f594d8c to your computer and use it in GitHub Desktop.
nc/socat like raw socket access to HTTPS
import trio
DOMAIN = "example.com"
PATH = "/"
async def main():
s0 = await trio.open_ssl_over_tcp_stream(DOMAIN, 443, https_compatible=True)
# Request a connection to the website
await s0.send_all(f"GET {PATH} HTTP/1.1\r\nHost: {DOMAIN}\r\n\r\n".encode())
async for chunk in s0:
print(f"=> {chunk}")
if __name__ == '__main__':
trio.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment