Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-cookie-agent

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-cookie-agent - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0

33

dist/http/create_cookie_agent.js

@@ -7,13 +7,7 @@ "use strict";

exports.createCookieAgent = createCookieAgent;
var _nodeUrl = _interopRequireDefault(require("node:url"));
var _create_cookie_header_value = require("../utils/create_cookie_header_value");
var _save_cookies_from_header = require("../utils/save_cookies_from_header");
var _validate_cookie_options = require("../utils/validate_cookie_options");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const kCookieOptions = Symbol('cookieOptions');

@@ -23,3 +17,2 @@ const kReimplicitHeader = Symbol('reimplicitHeader');

const kOverrideRequest = Symbol('overrideRequest');
function createCookieAgent(BaseAgentClass) {

@@ -33,29 +26,20 @@ // @ts-expect-error ...

super(options, ...rest);
if (cookieOptions) {
(0, _validate_cookie_options.validateCookieOptions)(cookieOptions);
}
this[kCookieOptions] = cookieOptions;
}
[kReimplicitHeader](req) {
const _headerSent = req._headerSent;
req._header = null;
req._implicitHeader();
req._headerSent = _headerSent;
}
[kRecreateFirstChunk](req) {
const firstChunk = req.outputData[0];
if (req._header == null || firstChunk == null) {
return;
}
const prevData = firstChunk.data;
const prevHeaderLength = prevData.indexOf('\r\n\r\n');
if (prevHeaderLength === -1) {

@@ -66,12 +50,8 @@ firstChunk.data = req._header;

}
const diffSize = firstChunk.data.length - prevData.length;
req.outputSize += diffSize;
req._onPendingData(diffSize);
}
[kOverrideRequest](req, requestUrl, cookieOptions) {
const _implicitHeader = req._implicitHeader.bind(req);
req._implicitHeader = () => {

@@ -84,3 +64,2 @@ try {

});
if (cookieHeader) {

@@ -93,8 +72,5 @@ req.setHeader('Cookie', cookieHeader);

}
return _implicitHeader();
};
const emit = req.emit.bind(req);
req.emit = (event, ...args) => {

@@ -114,10 +90,7 @@ if (event === 'response') {

}
return emit(event, ...args);
};
}
addRequest(req, options) {
const cookieOptions = this[kCookieOptions];
if (cookieOptions) {

@@ -130,9 +103,6 @@ try {

});
this[kOverrideRequest](req, requestUrl, cookieOptions);
if (req._header != null) {
this[kReimplicitHeader](req);
}
if (req._headerSent) {

@@ -146,9 +116,6 @@ this[kRecreateFirstChunk](req);

}
return super.addRequest(req, options);
}
}
return CookieAgent;
}

4

dist/http/http_cookie_agent.js

@@ -7,10 +7,6 @@ "use strict";

exports.HttpCookieAgent = void 0;
var _nodeHttp = _interopRequireDefault(require("node:http"));
var _create_cookie_agent = require("./create_cookie_agent");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const HttpCookieAgent = (0, _create_cookie_agent.createCookieAgent)(_nodeHttp.default.Agent);
exports.HttpCookieAgent = HttpCookieAgent;

@@ -7,10 +7,6 @@ "use strict";

exports.HttpsCookieAgent = void 0;
var _nodeHttps = _interopRequireDefault(require("node:https"));
var _create_cookie_agent = require("./create_cookie_agent");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const HttpsCookieAgent = (0, _create_cookie_agent.createCookieAgent)(_nodeHttps.default.Agent);
exports.HttpsCookieAgent = HttpsCookieAgent;

@@ -36,9 +36,5 @@ "use strict";

});
var _create_cookie_agent = require("./create_cookie_agent");
var _http_cookie_agent = require("./http_cookie_agent");
var _https_cookie_agent = require("./https_cookie_agent");
var _mixed_cookie_agent = require("./mixed_cookie_agent");

@@ -7,11 +7,6 @@ "use strict";

exports.MixedCookieAgent = void 0;
var _agentBase = _interopRequireDefault(require("agent-base"));
var _http_cookie_agent = require("./http_cookie_agent");
var _https_cookie_agent = require("./https_cookie_agent");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class MixedCookieAgent extends _agentBase.default.Agent {

@@ -23,9 +18,6 @@ constructor(options) {

}
callback(_req, options) {
return options.secureEndpoint ? this._httpsAgent : this._httpAgent;
}
}
exports.MixedCookieAgent = MixedCookieAgent;

21

dist/undici/cookie_agent.js

@@ -7,9 +7,5 @@ "use strict";

exports.CookieAgent = void 0;
var _undici = require("undici");
var _validate_cookie_options = require("../utils/validate_cookie_options");
var _cookie_client = require("./cookie_client");
class CookieAgent extends _undici.Agent {

@@ -23,16 +19,17 @@ constructor({

}
if (cookieOpts) {
(0, _validate_cookie_options.validateCookieOptions)(cookieOpts);
}
function factory(origin, opts) {
if (opts && opts.connections === 1) {
return new _cookie_client.CookieClient(origin, { ...opts,
return new _cookie_client.CookieClient(origin, {
...opts,
cookies: cookieOpts
});
} else {
return new _undici.Pool(origin, { ...opts,
return new _undici.Pool(origin, {
...opts,
factory: (origin, opts) => {
return new _cookie_client.CookieClient(origin, { ...opts,
return new _cookie_client.CookieClient(origin, {
...opts,
cookies: cookieOpts

@@ -44,10 +41,8 @@ });

}
super({ ...agentOpts,
super({
...agentOpts,
factory
});
}
}
exports.CookieAgent = CookieAgent;

@@ -8,19 +8,9 @@ "use strict";

exports.createCookieClient = createCookieClient;
var _undici = require("undici");
var _symbols = require("undici/lib/core/symbols");
var _redirect = require("undici/lib/handler/redirect");
var _create_cookie_header_value = require("../utils/create_cookie_header_value");
var _validate_cookie_options = require("../utils/validate_cookie_options");
var _cookie_handler = require("./cookie_handler");
var _convert_to_headers_object = require("./utils/convert_to_headers_object");
const kCookieOptions = Symbol('cookieOptions');
function createCookieClient(BaseClientClass) {

@@ -34,3 +24,2 @@ // @ts-expect-error ...

super(url, options);
if (cookieOpts) {

@@ -41,3 +30,2 @@ (0, _validate_cookie_options.validateCookieOptions)(cookieOpts);

}
[_symbols.kDispatch](opts, handler) {

@@ -47,12 +35,10 @@ const {

} = opts;
if (maxRedirections) {
opts = { ...opts,
opts = {
...opts,
maxRedirections: 0
};
handler = new _redirect.RedirectHandler(this, maxRedirections, opts, handler);
handler = new _undici.RedirectHandler(this, maxRedirections, opts, handler);
}
const cookieOptions = this[kCookieOptions];
if (cookieOptions) {

@@ -67,8 +53,7 @@ const origin = opts.origin || this[_symbols.kUrl].origin;

});
if (cookieHeader) {
headers['cookie'] = cookieHeader;
}
opts = { ...opts,
opts = {
...opts,
headers

@@ -78,12 +63,8 @@ };

}
return super[_symbols.kDispatch](opts, handler);
}
}
return CookieClient;
}
const CookieClient = createCookieClient(_undici.Client);
exports.CookieClient = CookieClient;

@@ -7,13 +7,8 @@ "use strict";

exports.CookieHandler = void 0;
var _undici = require("undici");
var _save_cookies_from_header = require("../utils/save_cookies_from_header");
var _convert_to_headers_object = require("./utils/convert_to_headers_object");
const kRequestUrl = Symbol('requestUrl');
const kCookieOptions = Symbol('cookieOptions');
const kHandlers = Symbol('handlers');
class CookieHandler {

@@ -25,6 +20,4 @@ constructor(requestUrl, cookieOptions, handlers) {

}
onConnect = abort => {
var _this$kHandlers$onCon, _this$kHandlers;
(_this$kHandlers$onCon = (_this$kHandlers = this[kHandlers]).onConnect) === null || _this$kHandlers$onCon === void 0 ? void 0 : _this$kHandlers$onCon.call(_this$kHandlers, abort);

@@ -34,3 +27,2 @@ };

var _this$kHandlers$onErr, _this$kHandlers2;
(_this$kHandlers$onErr = (_this$kHandlers2 = this[kHandlers]).onError) === null || _this$kHandlers$onErr === void 0 ? void 0 : _this$kHandlers$onErr.call(_this$kHandlers2, err);

@@ -40,3 +32,2 @@ };

var _this$kHandlers$onUpg, _this$kHandlers3;
(_this$kHandlers$onUpg = (_this$kHandlers3 = this[kHandlers]).onUpgrade) === null || _this$kHandlers$onUpg === void 0 ? void 0 : _this$kHandlers$onUpg.call(_this$kHandlers3, statusCode, headers, socket);

@@ -48,3 +39,2 @@ };

}
const headers = (0, _convert_to_headers_object.convertToHeadersObject)(_headers);

@@ -55,4 +45,5 @@ (0, _save_cookies_from_header.saveCookiesFromHeader)({

requestUrl: this[kRequestUrl]
}); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this[kHandlers].onHeaders(statusCode, _headers, resume);

@@ -63,5 +54,4 @@ };

throw new _undici.errors.InvalidArgumentError('invalid onData method');
} // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this[kHandlers].onData(chunk);

@@ -71,3 +61,2 @@ };

var _this$kHandlers$onCom, _this$kHandlers4;
(_this$kHandlers$onCom = (_this$kHandlers4 = this[kHandlers]).onComplete) === null || _this$kHandlers$onCom === void 0 ? void 0 : _this$kHandlers$onCom.call(_this$kHandlers4, trailers);

@@ -77,7 +66,5 @@ };

var _this$kHandlers$onBod, _this$kHandlers5;
(_this$kHandlers$onBod = (_this$kHandlers5 = this[kHandlers]).onBodySent) === null || _this$kHandlers$onBod === void 0 ? void 0 : _this$kHandlers$onBod.call(_this$kHandlers5, chunkSize, totalBytesSent);
};
}
exports.CookieHandler = CookieHandler;

@@ -24,5 +24,3 @@ "use strict";

});
var _cookie_agent = require("./cookie_agent");
var _cookie_client = require("./cookie_client");

@@ -7,8 +7,5 @@ "use strict";

exports.convertToHeadersObject = convertToHeadersObject;
var _undici = require("undici");
function convertToHeadersObject(_headers) {
const headers = {};
if (Array.isArray(_headers)) {

@@ -18,11 +15,8 @@ if (_headers.length % 2 !== 0) {

}
for (let idx = 0; idx < _headers.length; idx += 2) {
const key = _headers[idx];
const value = _headers[idx + 1];
if (key != null && value != null) {
const keyStr = (Buffer.isBuffer(key) ? key.toString('utf-8') : key).toLowerCase();
const valueStr = Buffer.isBuffer(value) ? value.toString('utf-8') : value;
if (keyStr === 'set-cookie') {

@@ -40,4 +34,3 @@ headers[keyStr] = [...(headers[keyStr] ?? []), valueStr];

}
return headers;
}

@@ -7,5 +7,3 @@ "use strict";

exports.createCookieHeaderValue = createCookieHeaderValue;
var _toughCookie = require("tough-cookie");
function createCookieHeaderValue({

@@ -20,7 +18,7 @@ cookieOptions,

} = cookieOptions;
const getCookiesSync = async_UNSTABLE ? // eslint-disable-next-line @typescript-eslint/no-var-requires
const getCookiesSync = async_UNSTABLE ?
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('deasync')(jar.getCookies.bind(jar)) : jar.getCookiesSync.bind(jar);
const cookies = getCookiesSync(requestUrl);
const cookiesMap = new Map(cookies.map(cookie => [cookie.key, cookie]));
for (const passedValue of passedValues) {

@@ -30,6 +28,4 @@ if (typeof passedValue !== 'string') {

}
for (const str of passedValue.split(';')) {
const cookie = _toughCookie.Cookie.parse(str.trim());
if (cookie != null) {

@@ -40,5 +36,4 @@ cookiesMap.set(cookie.key, cookie);

}
const cookieHeaderValue = Array.from(cookiesMap.values()).map(cookie => cookie.cookieString()).join(';\x20');
return cookieHeaderValue;
}

@@ -7,3 +7,2 @@ "use strict";

exports.saveCookiesFromHeader = saveCookiesFromHeader;
function saveCookiesFromHeader({

@@ -18,5 +17,5 @@ cookieOptions,

} = cookieOptions;
const setCookieSync = async_UNSTABLE ? // eslint-disable-next-line @typescript-eslint/no-var-requires
const setCookieSync = async_UNSTABLE ?
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('deasync')(jar.setCookie.bind(jar)) : jar.setCookieSync.bind(jar);
for (const cookie of [cookies].flat()) {

@@ -26,3 +25,2 @@ if (cookie == null) {

}
setCookieSync(cookie, requestUrl, {

@@ -29,0 +27,0 @@ ignoreError: true

@@ -7,4 +7,4 @@ "use strict";

exports.validateCookieOptions = validateCookieOptions;
function validateCookieOptions( // eslint-disable-next-line @typescript-eslint/no-explicit-any
function validateCookieOptions(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
opts, resolver = require.resolve) {

@@ -14,3 +14,2 @@ if (!('jar' in opts)) {

}
if (opts.async_UNSTABLE) {

@@ -17,0 +16,0 @@ try {

{
"name": "http-cookie-agent",
"version": "4.0.2",
"version": "5.0.0",
"description": "Allows cookies with every Node.js HTTP clients.",

@@ -56,3 +56,4 @@ "keywords": [

"format:eslint": "eslint --fix --ext .js,.ts,.mjs,.mts .",
"format:prettier": "prettier --write ."
"format:prettier": "prettier --write .",
"patch-package": "patch-package"
},

@@ -70,37 +71,38 @@ "ava": {

"devDependencies": {
"@3846masa/configs": "github:3846masa/configs#8ae5f7cc4740f9fc2f9d773dcb91ec920a1e7fe2",
"@babel/cli": "^7.18.9",
"@babel/core": "7.18.9",
"@babel/preset-env": "^7.18.9",
"@babel/preset-typescript": "^7.18.6",
"@3846masa/configs": "github:3846masa/configs#8a58b51d1ee96d29ce9cfddc5eb490aa45fb1e37",
"@babel/cli": "7.20.7",
"@babel/core": "7.20.7",
"@babel/preset-env": "7.20.2",
"@babel/preset-typescript": "7.18.6",
"@hapi/wreck": "18.0.0",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/changelog": "6.0.2",
"@semantic-release/git": "10.0.1",
"@types/deasync": "0.1.2",
"@types/needle": "2.5.3",
"@types/node": "14.18.22",
"@types/needle": "3.2.0",
"@types/node": "14.18.35",
"@types/request": "2.48.8",
"@types/semver": "^7.3.10",
"@types/superagent": "4.1.15",
"@types/semver": "7.3.13",
"@types/superagent": "4.1.16",
"@types/tough-cookie": "4.0.2",
"agentkeepalive": "4.2.1",
"ava": "4.3.1",
"ava": "4.3.3",
"axios": "0.27.2",
"deasync": "0.1.27",
"got": "12.1.0",
"deasync": "0.1.28",
"got": "12.5.3",
"http-proxy-agent": "5.0.0",
"needle": "3.1.0",
"node-fetch": "3.2.9",
"needle": "3.2.0",
"node-fetch": "3.3.0",
"npm-run-all": "4.1.5",
"phin": "3.6.1",
"patch-package": "6.5.0",
"phin": "3.7.0",
"proxy": "1.0.2",
"request": "2.88.2",
"rimraf": "^3.0.2",
"semantic-release": "19.0.3",
"semver": "^7.3.7",
"superagent": "8.0.0",
"tough-cookie": "4.0.0",
"typescript": "4.7.4",
"undici": "5.8.0",
"urllib": "3.0.4"
"rimraf": "3.0.2",
"semantic-release": "19.0.5",
"semver": "7.3.8",
"superagent": "8.0.6",
"tough-cookie": "4.1.2",
"typescript": "4.9.4",
"undici": "5.14.0",
"urllib": "3.10.0"
},

@@ -110,3 +112,3 @@ "peerDependencies": {

"tough-cookie": "^4.0.0",
"undici": "^5.1.1"
"undici": "^5.11.0"
},

@@ -113,0 +115,0 @@ "peerDependenciesMeta": {

import type { CookieJar } from 'tough-cookie';
import type { Agent, Client } from 'undici';
import { Agent, Client } from 'undici';

@@ -4,0 +4,0 @@ export interface CookieOptions {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc