class_docstr: A tiny, hacky http(s) server for testing ship logs.
  
  It's about the same amount of code as subclassing the stdlib's SimpleHTTPRequestHandler, but it
  shuts down much faster.
class_docstr_tok: ["A","tiny",",","hacky","http","(","s",")","server","for","testing","ship","logs",".","It","'s","about","the","same","amount","of","code","as","subclassing","the","stdlib","'s","SimpleHTTPRequestHandler",",","but","it","shuts","down","much","faster","."]
code: def serve_one_request(self, s: socket.socket) -> None:
      # Receive headers.
      hdrs = b""
      while b"\r\n\r\n" not in hdrs:
          buf = s.recv(4096)
          if not buf:
              # EOF
              return
          hdrs += buf
      # Detect the initial GET /api/v1/me probe.
      if hdrs.startswith(b"GET"):
          s.sendall(b"HTTP/1.1 200 OK\r\n\r\n")
          return
      # Are we supposed to misbehave?
      if self.reject_logs:
          s.sendall(b"HTTP/1.1 500 No! I don't wanna!\r\n\r\n")
          return
      # Receive body until we have valid json.
      hdrs, body = hdrs.split(b"\r\n\r\n", maxsplit=1)
      while True:
          try:
              jbody = json.loads(body)
              break
          except json.decoder.JSONDecodeError:
              # Must not have the full body yet.
              pass
          buf = s.recv(4096)
          if not buf:
              # EOF
              return
          body += buf
  
      # Remember the logs we saw.
      self.logs.extend(j["log"] for j in jbody["logs"])
  
      # Send a response.
      s.sendall(b"HTTP/1.1 200 OK\r\n\r\n")
  
imports: import io
  import json
  import logging
  import os
  import shutil
  import signal
  import socket
  import ssl
  import subprocess
  import sys
  import tempfile
  import textwrap
  import threading
  import time
  from typing import Any, List, Optional
  import pytest
label_desc: Use image node_id 5 for calling the ShipLogServer obj's underlying member method code with example usage: obj.serve_one_request(s) without return types