Handle GET requests.
(self)
| 49 | self.wfile.write(text.encode()) |
| 50 | |
| 51 | def do_GET(self) -> None: |
| 52 | """Handle GET requests.""" |
| 53 | if self.path == "/": |
| 54 | # Root endpoint - HTML welcome page |
| 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 | # Mimic httpbin.org/json - slideshow data |
| 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 | # Mimic httpbin.org/get - echo request information |
| 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 |
nothing calls this directly
no test coverage detected