code: def _http_tunnel_listener(
      master_addr: str,
      tunnel: ListenerConfig,
      cert_file: Union[str, bool, None],
      cert_name: Optional[str],
      authorization_token: Optional[str] = None,
  ) -> socketserver.ThreadingTCPServer:
      parsed_master = request.parse_master_address(master_addr)
      assert (
          parsed_master.hostname is not None
      ), "Failed to parse master address: {}".format(master_addr)
  
      url = request.make_url(
          master_addr, "proxy/{}/".format(tunnel.service_id)
      )
  
      class TunnelHandler(socketserver.BaseRequestHandler):
          def handle(self) -> None:
              proxies = (
                  {} if urllib.request.proxy_bypass(parsed_master.hostname) else None  # type: ignore
              )
  
              ws = lomond.WebSocket(
                  request.maybe_upgrade_ws_scheme(url), proxies=proxies
              )
              if authorization_token is not None:
                  ws.add_header(
                      b"Authorization",
                      f"Bearer {authorization_token}".encode(),
                  )
              # We can't send data to the WebSocket before the connection becomes ready,
              # which takes a bit of time; this semaphore lets the sending thread
              # wait for that to happen.
              ready_sem = threading.Semaphore(0)
  
              c1 = threading.Thread(
                  target=copy_to_websocket2,
                  args=(ws, self.request, ready_sem),
              )
              c2 = threading.Thread(
                  target=copy_from_websocket2,
                  args=(
                      self.request,
                      ws,
                      ready_sem,
                      cert_file,
                      cert_name,
                  ),
              )
              c1.start()
              c2.start()
              c1.join()
              c2.join()
  
      socket_class = ReuseAddrServer
      if sys.platform == "win32":
          # On Windows, SO_REUSEADDR is a security issue:
          # https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse#application-strategies
          socket_class = socketserver.ThreadingTCPServer
  
      return socket_class(
          (tunnel.local_addr, tunnel.local_port), TunnelHandler
      )
  
imports: from __future__ import annotations
  import contextlib
  import io
  import os
  import socket
  import socketserver
  import ssl
  import sys
  import threading
  import time
  import urllib.request
  from dataclasses import dataclass
  from typing import Iterator, List, Optional, Union
  import lomond
  from determined.common.api import Session, authentication, bindings, request
label_desc: Use image node_id 6 for calling a global function with example usage: _http_tunnel_listener(master_addr, tunnel, cert_file, cert_name, authorization_token) and returns: socket_class