#!/usr/bin/env python3 """ Simple authenticated web server for LangMem documentation """ import http.server import socketserver import base64 import os from urllib.parse import parse_qs # Authentication credentials USERNAME = "langmem" PASSWORD = "langmem2025" class AuthHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): """HTTP handler with basic authentication""" def __init__(self, *args, **kwargs): super().__init__(*args, directory="docs", **kwargs) def do_GET(self): """Handle GET requests with authentication""" if self.authenticate(): super().do_GET() else: self.send_auth_request() def authenticate(self): """Check if request has valid authentication""" auth_header = self.headers.get('Authorization') if not auth_header: return False try: auth_type, credentials = auth_header.split(' ', 1) if auth_type.lower() != 'basic': return False decoded = base64.b64decode(credentials).decode('utf-8') username, password = decoded.split(':', 1) return username == USERNAME and password == PASSWORD except Exception: return False def send_auth_request(self): """Send authentication request to client""" self.send_response(401) self.send_header('WWW-Authenticate', 'Basic realm="LangMem Documentation"') self.send_header('Content-type', 'text/html') self.end_headers() html = """
Authentication required to access documentation.
Username: langmem
Password: langmem2025
Please refresh the page and enter your credentials when prompted.