code: def make_request_handler(long_poller, directory):
      class RequestHandler(http.server.SimpleHTTPRequestHandler):
          """
          RequestHandler is how we implement custom HTTP server behavior for GET and POST.
          """
  
          def __init__(self, *args):
              super().__init__(*args, directory=directory)
  
          def do_GET(self) -> None:
              """
              GET should inject snippets of javascript into static html pages.
              """
              path = self.translate_path(self.path)
              if path.startswith("site/html/") and os.path.isdir(path):
                  path = os.path.join(path, "index.html")
              if path.endswith(".html"):
                  # HTML documents get our client-side update script injected into them.
                  try:
                      f = open(path, "rb")
                  except OSError:
                      self.send_error(404, "file not found")
                      return None
                  try:
                      stat = os.fstat(f.fileno())
                      body = f.read()
                  finally:
                      f.close()
  
                  # Inject the refresh script.
                  body = body.replace(
                      b"<!--dev-reload-script-location-->",
                      make_refresh_script(path, stat.st_mtime),
                  )
  
                  self.send_response(200)
                  self.send_header("Content-Length", str(len(body)))
                  self.send_header("Content-type", "text/html")
                  self.send_header(
                      "Last-Modified",
                      self.date_time_string(stat.st_mtime),
                  )
                  self.end_headers()
  
                  self.wfile.write(body)
                  return None
  
              # Otherwise, use the default logic (mostly for downloads).
              return super().do_GET()
  
          def do_POST(self) -> None:
              """
              POST is exclusively for pages to long-poll for updates.
              """
              x_rebuild_time = self.headers["X-rebuild-time"]
              path = self.headers["X-rebuild-path"]
              assert x_rebuild_time and path
              new = long_poller.wait(path, x_rebuild_time)
              response = b"new" if new else b"old"
              try:
                  self.send_response(200)
                  self.send_header("Content-type", "application/text")
                  self.send_header("Content-Length", str(len(response)))
                  self.end_headers()
                  self.wfile.write(response)
              except BrokenPipeError:
                  # after waiting for so long, the client may have disconnected
                  pass
  
      return RequestHandler
  
imports: import http.server
  import os
  import subprocess
  import sys
  import threading
  import time
  import watchdog
  import watchdog.events
  import watchdog.observers
label_desc: Use image node_id 2 for calling a global function with example usage: make_request_handler(long_poller, directory) and returns: RequestHandler, super, None, None