51 def do_GET(self) -> None:
52 """Handle GET requests."""
53 if self.path == "/":
54
55 html = """<!DOCTYPE html>
56<html>
57<head><title>FastLED Test Server</title></head>
58<body>
59<h1>FastLED HTTP Test Server</h1>
60<p>This server mimics httpbin.org endpoints for testing FastLED fetch API.</p>
61<h2>Available Endpoints:</h2>
62<ul>
63<li><a href="/json">/json</a> - Sample JSON slideshow data</li>
64<li><a href="/get">/get</a> - Echo request information</li>
65<li><a href="/ping">/ping</a> - Health check (returns "pong")</li>
66</ul>
67</body>
68</html>"""
69 self.send_text_response(html)
70
71 elif self.path == "/json":
72
73 data = {
74 "slideshow": {
75 "author": "FastLED Community",
76 "title": "FastLED Tutorial",
77 "slides": [
78 {
79 "title": "Introduction to FastLED",
80 "type": "tutorial",
81 },
82 {
83 "title": "LED Basics",
84 "type": "lesson",
85 },
86 {
87 "title": "HTTP Fetch API",
88 "type": "demo",
89 },
90 ],
91 }
92 }
93 console.print("[green]→ /json - Returning slideshow data[/green]")
94 self.send_json_response(data)
95
96 elif self.path.startswith("/get"):
97
98 query_params: dict[str, str] = {}
99 if "?" in self.path:
100 query_string = self.path.split("?", 1)[1]
101 for param in query_string.split("&"):
102 if "=" in param:
103 key, value = param.split("=", 1)
104 query_params[key] = value
105
106 headers: dict[str, str] = {}
107 for header_name, header_value in self.headers.items():
108 headers[header_name] = header_value
109
110 data: dict[str, Any] = {
111 "args": query_params,
112 "headers": headers,
113 "origin": self.client_address[0],
114 "url": f"http://{self.headers.get('Host', 'localhost')}{self.path}",
115 }
116 console.print("[green]→ /get - Returning request info[/green]")
117 self.send_json_response(data)
118
119 elif self.path == "/ping":
120
121 console.print("[green]→ /ping - Health check[/green]")
122 self.send_text_response("pong\n")
123
124 else:
125
126 console.print(f"[red]→ {self.path} - Not Found[/red]")
127 self.send_json_response(
128 {"error": "Not Found", "path": self.path}, status_code=404
129 )
130