Skip to content
Back to skills

Node Http

ASecurity

Rules for a Node.js HTTP server built on node:http itself (http.createServer, no Express, Fastify or Koa): requests Node answers on its own, client errors, CONNECT, Expect, pipelining, half-close, reading a declared body before replying, and in-process tests for them. For the backend section.

  • 14 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 18, 2026
ai-agentsgonodeexpressbackend

Works with

  • cli

Security analysis

A100/100

Scanned November 18, 2026

npx -y skills add afel6/section-team --skill node-http --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Node Http?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Node Http
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/afel6-node-http/badge)](https://www.skillsdirectory.com/skills/afel6-node-http)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: node-http
description: Rules for a Node.js HTTP server built on node:http itself (http.createServer, no Express, Fastify or Koa): requests Node answers on its own, client errors, CONNECT, Expect, pipelining, half-close, reading a declared body before replying, and in-process tests for them. For the backend section.
---
# node:http servers

node:http answers some requests itself (an unknown Expect: a bare 417; CONNECT: the socket closes with no reply; a method it does not know or a broken request line: a bare 400): where the spec says how every request is answered, send those through your handler too (on 'clientError' a handler given (err, socket) answers the last: err.code, such as HPE_INVALID_METHOD, says why and err.rawPacket holds the bytes the parser was given, which can begin with earlier requests sent in the same write (pipelining); it writes the reply to the socket by hand and ends it, after the replies to the requests that had fully arrived before the refused one, and at once for an error in a request still arriving (a broken body, or one that timed out); the same order holds on 'connect' (res.assignSocket throws while an earlier reply holds the socket): test a valid request and an unknown method, and a valid request and a CONNECT, each pair sent in one write; with a listener set, Node answers no client error itself, so answer each code: the spec's reply where the spec covers it, else the one Node would have sent (400; 431 for HPE_HEADER_OVERFLOW; 408 for ERR_HTTP_REQUEST_TIMEOUT), and when socket.writable is false or the code is ECONNRESET write nothing and call socket.destroy(); server.on('checkExpectation', handler); on 'connect' when the spec answers CONNECT as an ordinary request rather than opening a tunnel, run the handler on a new http.ServerResponse(req) given the socket by res.assignSocket(socket), with res.shouldKeepAlive = false, socket.on('error', () => socket.destroy()) and socket.end() on the reply's 'finish', else a client reset crashes the process and the socket never closes).

A client that ends its sending side once its request is out (a half-close) gets its reply too: set server.httpAllowHalfOpen = true, or Node closes the connection with no reply whenever the handler waits.

A reply you write on these paths keeps every rule the spec gives replies: where the spec has the whole request body read before any reply, first count the bytes the request declares and drop them, keeping none the reply does not need (its Content-Length, or each chunk by its size up to the zero chunk; on 'clientError' err.rawPacket holds what has come, and the rest comes as 'data' once you replace the socket's own 'data' and 'end' listeners (Node's 'end' listener ends the socket, or marks an earlier reply as the last, at a half-close); on 'connect' the body starts in head and goes on at the socket), reply at once when it declares none, and send no reply before every declared byte has come unless the body breaks: a body that cannot come (a chunk size that is not hex, or the client ends its side first) is a broken body, answered at once as above, and a body still on its way waits for the limit Node keeps for every request, server.requestTimeout (300 s by default, 0 for none), never a shorter one of your own, which would answer a body still on its way; at that limit answer as Node does on its own sockets (408, written by hand, socket ended).

On 'connect' Node no longer times the socket, and on 'clientError' it raises one more client error for that socket (ERR_HTTP_REQUEST_TIMEOUT once server.headersTimeout has passed, 60 s by default): ignore later errors on a socket you took over (a WeakSet of them), drop its 'timeout' listeners (socket.removeAllListeners('timeout')), or Node's keep-alive timer closes it with no reply keepAliveTimeout + 1 s after an earlier reply on that connection, and keep your own timer there at server.requestTimeout, cleared when the socket closes.

Test it in-process on a server the test creates with http.createServer({ headersTimeout: 300, requestTimeout: 1000, connectionsCheckingInterval: 50 }): an unknown method whose body comes 0.5 s after its headers gets its reply after the body, and one whose body never comes gets the 408 only after 1 s (1 s is the limit the test sets: assert it as a time the spec names, with a margin that is a fraction of it); write those two framings in a few lines, not a general parser.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.