Skip to content

Instantly share code, notes, and snippets.

@mosk-it
Last active May 22, 2025 00:26
Show Gist options
  • Save mosk-it/0237ce7e2db2ed9c8fe3d2e0a604d9c5 to your computer and use it in GitHub Desktop.
Save mosk-it/0237ce7e2db2ed9c8fe3d2e0a604d9c5 to your computer and use it in GitHub Desktop.
from http.server import BaseHTTPRequestHandler, HTTPServer
import base64
SERVER_IP = "0.0.0.0"
PUBLIC_IP = "192.168.0.206"
PORT = 8002
USERNAME = "foo"
PASSWORD = "bar"
AUTH = base64.b64encode(f"{USERNAME}:{PASSWORD}".encode()).decode()
class AuthHandler(BaseHTTPRequestHandler):
def check_auth(self):
if self.headers.get("Authorization") != f"Basic {AUTH}":
self.send_response(401)
self.send_header("WWW-Authenticate", 'Basic realm="Podcast"')
self.end_headers()
return False
return True
def do_GET(self):
if not self.check_auth():
return
self.send_response(200)
if self.path == "/feed.xml":
self.send_header("Content-type", "application/xml")
self.end_headers()
self.wfile.write(f"""<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Auth Test</title>
<image><url>http://{PUBLIC_IP}:{PORT}/logo.png</url></image>
</channel>
</rss>""".encode())
elif self.path == "/logo.png":
self.send_header("Content-type", "image/png")
self.end_headers()
with open("logo.png", "rb") as f:
self.wfile.write(f.read())
if __name__ == "__main__":
print(f"Auth server running at http://{PUBLIC_IP}:{PORT}")
print(f"Feed URL: http://{PUBLIC_IP}:{PORT}/feed.xml")
print(f"Credentials: {USERNAME}/{PASSWORD}")
HTTPServer((SERVER_IP, PORT), AuthHandler).serve_forever()
from http.server import BaseHTTPRequestHandler, HTTPServer
SERVER_IP = "0.0.0.0"
PUBLIC_IP = "192.168.0.206"
PORT = 8001
class OpenHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
if self.path == "/feed.xml":
self.send_header("Content-type", "application/xml")
self.end_headers()
self.wfile.write(f"""<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Open Test</title>
<image><url>http://{PUBLIC_IP}:{PORT}/logo.png</url></image>
</channel>
</rss>""".encode())
elif self.path == "/logo.png":
self.send_header("Content-type", "image/png")
self.end_headers()
with open("logo.png", "rb") as f:
self.wfile.write(f.read())
if __name__ == "__main__":
print(f"Open server running at http://{PUBLIC_IP}:{PORT}")
print(f"Feed URL: http://{PUBLIC_IP}:{PORT}/feed.xml")
HTTPServer((SERVER_IP, PORT), OpenHandler).serve_forever()
@mosk-it
Copy link
Author

mosk-it commented May 22, 2025

logo.png image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment