Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/testing/performance/mobile-startup/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 1 kB image not shown  

Quelle  http2-server.js   Sprache: JAVA

 

#!/usr/bin/env node

const http2 = require("http2");
const fs = require("fs");
const path = require("path");

const [directory = ".", certFile, keyFile] = process.argv.slice(2);
const opts = certFile
  ? { cert: fs.readFileSync(certFile), key: fs.readFileSync(keyFile) }
  : {};
const server = certFile ? http2.createSecureServer(opts) : http2.createServer();

server.on("stream", (stream, headers) => {
  const reqPath = headers[":path"];
  let filePath = path.join(directory, reqPath);
  if (
    !path.resolve(filePath).startsWith(path.resolve(directory) + path.sep) &&
    path.resolve(filePath) !== path.resolve(directory)
  ) {
    stream.respond({ ":status": 403 });
    stream.end();
    return;
  }
  if (filePath.endsWith("/")) {
    filePath += "index.html";
  }

  console.log(`${headers[":method"]} ${reqPath}`);

  const ext = path.extname(filePath);
  const contentType =
    {
      ".html": "text/html",
      ".js": "application/javascript",
      ".css": "text/css",
      ".json": "application/json",
      ".png": "image/png",
      ".jpg": "image/jpeg",
      ".gif": "image/gif",
      ".svg": "image/svg+xml",
      ".ico": "image/x-icon",
    }[ext] || "application/octet-stream";

  fs.createReadStream(filePath)
    .on("error", () => {
      stream.respond({ ":status": 404 });
      stream.end();
    })
    .on("open", () => {
      stream.respond({ ":status": 200, "content-type": contentType });
    })
    .pipe(stream);
});

const protocol = certFile ? "https" : "http";
server.listen(8000, () => {
  console.log(`HTTP/2 server (${protocol}) listening on port 8000`);
  console.log(`Serving files from: ${path.resolve(directory)}`);
});

server.on("error", err => {
  console.error("Server error:", err);
});

Messung
CHZG
859710094

¤ Dauer der Verarbeitung: 0.2 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.