Перейти к содержимому

Эта страница ещё не переведена и показана на английском.

node:http

How Elide supports Node's http and https: the HTTP/1.1 server and client and the HTTPS client; https.createServer and node:http2 are unavailable.

На этой странице
Open in ChatGPTOpen in Claude

node:http provides Node’s HTTP/1.1 server and client; node:https provides the client only. For a Fetch-style handler or HTTP/2, use Elide.serve.

Example

// http.mjs
import { createServer } from "node:http";

const server = createServer((req, res) => {
  res.writeHead(200, { "content-type": "text/plain" });
  res.end(`${req.method} ${req.url}\n`);
});

server.listen(0, "127.0.0.1", async () => {
  const { port } = server.address();
  const response = await fetch(`http://127.0.0.1:${port}/hello`);
  console.log(response.status, response.headers.get("content-type"));
  console.log(await response.text());
  server.close();
});

elide run http.mjs prints:

200 text/plain
GET /hello

Differences from Node

  • https.createServer throws ERR_HTTPS_SERVER_UNSUPPORTED; terminate TLS in front of http.createServer.
  • http.globalAgent defaults to keepAlive: true, maxSockets: Infinity, and maxFreeSockets: 256.
  • HTTPS certificate validation follows fetch.
  • node:http2 is unavailable.
  • --allow-net and --deny-net apply under the sandbox.

Samples

Reference

Status: Partial · Not measured

http exports

Agent, ClientRequest, IncomingMessage, OutgoingMessage, Server, ServerResponse, createServer, get, globalAgent, maxHeaderSize, request, setMaxIdleHTTPParsers, validateHeaderName, validateHeaderValue, 2 constants such as METHODS

Not implemented

CloseEvent, MessageEvent, WebSocket, setGlobalProxyFromEnv.

Была ли эта страница полезной?