http1.1
v2.2.2
Published
Pure-JS TLS 1.3 client + minimal HTTP/1.1 layer — zero work at require() time, flat hot path, X25519 + custom zero-alloc AES-GCM.
Maintainers
Readme
http1.1
Pure-JS TLS 1.3 client + minimal HTTP/1.1 layer for Node.js. Zero dependencies — only node:net, node:crypto, node:events.
Three flat files, one job each:
tls.js—RawTls13Socket: TLS 1.3 record layer (X25519, AES-128/256-GCM, HKDF-SHA256/384)http1.js— keep-alive pooled, pipelined HTTP/1.1 client (Agent,request,get)index.js— thin export surface
Features
- TLS 1.3 only: X25519 key exchange, AES-128/256-GCM, HKDF-SHA256/384
- Zero work at
require()time — the X25519 keypair pool starts lazily on firstconnect() - Flat hot path: preallocated scratch buffers, no per-record closures
Agentwith keep-alive connection pooling + HTTP pipelining (multiple requests in flight per connection, responses parsed strictly in order)- Minimal HTTP/1.1:
request()/get()withresponse/data/endevents, Content-Length + chunked decoding, 1xx/204/304/HEAD handling - No certificate validation (raw TLS socket); bring your own pinning if needed
Benchmarks (local TLS server, burst of N requests)
| | req/s |
|---|---|
| node https.Agent (keepAlive) | ~9.6k–11.1k |
| http1.1 Agent (keepAlive + pipelining + record coalescing) | ~15k–16.4k |
Install
npm install http1.1Usage
HTTP/1.1 request
import http from 'http1.1';
var req = http.get({ host: 'example.com', path: '/' }, function(res) {
console.log('status', res.statusCode);
res.on('data', function(c) { process.stdout.write(c); });
res.on('end', function() { console.log('\ndone'); });
});
req.on('error', console.error);
req.end();POST with body:
var req = http.request({ host: 'api.example.com', path: '/x', method: 'POST' }, cb);
req.end('payload');Keep-alive agent (recommended for many requests)
import http from 'http1.1';
var agent = new http.Agent({ maxSockets: 50 });
for (var i = 0; i < 100; i++) {
agent.request({ host: 'example.com', path: '/' }, function(res) {
res.resume ? res.resume() : res.on('data', function() {});
res.on('end', function() { console.log('done', res.statusCode); });
}).end();
}Connections are reused automatically; idle sockets are picked before opening new ones.
Raw TLS socket
import { RawTls13Socket } from 'http1.1';
var s = new TlsSocket({ host: 'example.com', alpn: ['h2', 'http/1.1'] });
s.on('secureConnect', function() {
console.log('alpn:', s.negotiatedAlpn);
s.write(Buffer.from('hello'));
});
s.on('data', function(d) { console.log('got', d.length, 'bytes'); });
s.connect();API
http.request(opts, cb)/http.get(opts, cb)→ returnsreq(EventEmitter); callreq.end(body?)to connect + send.cb(res)fires on response headers;resemitsdata/end.new http.Agent({maxSockets, pipelining})→ keep-alive pool;agent.request(opts, cb),agent.destroy().pipelining= max requests in flight per connection (default 16).new RawTls13Socket({host, port, ip, alpn})→.connect(),.write(buf),.destroy(),.destroyed; events:secureConnect,data,close,error,alert.
Notes
- TLS 1.3 only — TLS 1.2 servers are not supported.
- Client-side only (no server mode).
- Certificates are not validated — this is a raw cryptographic client.
