Update server.py

This commit is contained in:
Nova Cat 2025-01-12 22:37:07 -08:00
parent 1718891a06
commit 26f72c6fb0

View file

@ -1,5 +1,6 @@
#!/usr/bin/python3
import asyncio, traceback, socket, ssl
from urllib.parse import urlparse
from flask import Flask, request, redirect
from hypercorn.config import Config
from hypercorn.asyncio import serve
@ -34,8 +35,9 @@ def relay():
title = "Something went wrong..."
try:
gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
gemsocket = ssl.create_default_context().wrap_socket(gsocket)
gemsocket.connect((url, 1965))
fulladdr = "gemini://" + url
gemsocket = ssl.create_default_context().wrap_socket(gsocket, server_hostname=urlparse(fulladdr).hostname)
gemsocket.connect((urlparse(fulladdr).hostname, 1965))
gemsocket.send(bytes("gemini://" + url + "\r\n", "UTF-8"))
received = ""
while True: