private Void serveResponses(Socket socket) throws IOException {
    try (Socket ignored = socket) {
      InputStream in = socket.getInputStream();
      OutputStream out = socket.getOutputStream();

      int firstByte = in.read();
      int secondByte = in.read();
      if (!(firstByte == 'G' && secondByte == 'E')
          && !(firstByte == 'P' && secondByte == 'O')
          && !(firstByte == 'H' && secondByte == 'E')) { // GET, POST, HEAD, ...
        out.write(
            "HTTP/1.1 400 Bad Request\nContent-Length: 0\n\n".getBytes(StandardCharsets.UTF_8));
        return null;
      }

      BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
      for (int i = 0; true; i++) {
        for (String line = reader.readLine();
            line != null && !line.isEmpty(); // An empty line marks the end of an HTTP request.
            line = reader.readLine()) {
          synchronized (inputRead) {
            if (firstByte != -1) {
              inputRead.append((char) firstByte).append((char) secondByte);
              firstByte = -1;
            }
            inputRead.append(line).append('\n');
          }
        }
        String response = getNextResponse(i);
        if (response == null) {
          return null;
        }
        out.write(response.getBytes(StandardCharsets.UTF_8));
        out.flush();
      }
    }
  }
Simple local web server for testing.
jib-core/src/test/java/com/google/cloud/tools/jib/http/TestWebServer.java