Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,14 @@ Request.prototype._end = function () {
xhr.send(typeof data === 'undefined' ? null : data);
};

request.agent = () => new Agent();
// create a Proxy that can instantiate a new Agent without using `new` keyword
// (for backward compatibility and chaining)
const proxyAgent = new Proxy(Agent, {
apply(target, thisArg, argumentsList) {
return new target(...argumentsList);
}
});
request.agent = proxyAgent;

for (const method of ['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE']) {
Agent.prototype[method.toLowerCase()] = function (url, fn) {
Expand Down