"""Run with Python 3. Only binds loopback; Ctrl-C stops it.
Paths: /sample.json, /bad, /large, /missing, /slow. Synthetic data only."""
import http.server,time
class Handler(http.server.BaseHTTPRequestHandler):
 def do_GET(self):
  if self.path=='/chunked':
   self.send_response(200);self.send_header('Content-Length','1');self.send_header('Transfer-Encoding','chunked');self.end_headers()
   try:self.wfile.write(b'20000\r\n'+b'x'*131072+b'\r\n0\r\n\r\n')
   except (BrokenPipeError,ConnectionResetError):pass
   return
  if self.path=='/slow':time.sleep(3)
  body=b'{"source":"local HTTP fixture","stations":[{"name":"Garden","temperature":22.7},{"name":"Roof","temperature":20.1}],"online":true}'
  if self.path=='/bad':body=b'{bad json'
  if self.path=='/large':body=b' '*70000
  self.send_response(404 if self.path=='/missing' else 200)
  self.send_header('Content-Type','application/json');self.send_header('Content-Length',str(len(body)));self.end_headers()
  try:self.wfile.write(body)
  except (BrokenPipeError,ConnectionResetError):pass
 def log_message(self,*args):pass

print('Fixture: http://127.0.0.1:18765/sample.json')
http.server.ThreadingHTTPServer(('127.0.0.1',18765),Handler).serve_forever()
