Install
openclaw skills install agent-baseCreate custom http.Agent.
openclaw skills install agent-baseHelps users create custom http.Agent subclasses based on the agent-base module, for scenarios such as HTTP request proxying, custom socket connections, etc.
Use when the user needs to write HTTP/HTTPS/SOCKS/PAC proxies, custom HTTP connection logic, or extend http.Agent.
agent-base wraps an ordinary function into an http.Agent instance. It is an abstract class that requires defining the connect(req, opts) method to create the underlying Socket.
connect() can return any Duplex stream, or another http.Agent instance to delegate the requestconnect() can be an async functionopts.secureEndpoint is used to distinguish between HTTP / HTTPSimport * as net from 'net';
import * as tls from 'tls';
import * as http from 'http';
import { Agent } from 'agent-base';
class MyAgent extends Agent {
connect(req, opts) {
if (opts.secureEndpoint) {
return tls.connect(opts);
} else {
return net.connect(opts);
}
}
}
const agent = new MyAgent({ keepAlive: true });
http.get('http://nodejs.org/api/', { agent }, (res) => {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
connect() method based on the Agent abstract classSee references/proxy-details.md, which includes:
http-proxy-agent — HTTP endpoint proxyhttps-proxy-agent — HTTPS endpoint proxypac-proxy-agent — PAC file proxysocks-proxy-agent — SOCKS proxy