Last active
May 22, 2025 00:26
-
-
Save mosk-it/0237ce7e2db2ed9c8fe3d2e0a604d9c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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() |
This file contains hidden or 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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
logo.png