unprint 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Simplify common web scraping tasks while staying in control of the data.",
5
5
  "main": "src/app.js",
6
6
  "scripts": {},
package/src/app.js CHANGED
@@ -1056,6 +1056,14 @@ function getCookie(options) {
1056
1056
  return headerCookieData;
1057
1057
  }
1058
1058
 
1059
+ function filterHeaders(headers, options) {
1060
+ if (headers && options.defaultHeaders !== false) {
1061
+ return Object.fromEntries(Object.entries(headers).filter(([_key, value]) => value !== null));
1062
+ }
1063
+
1064
+ return headers;
1065
+ }
1066
+
1059
1067
  function curateResponse(res, data, options, { url, control, customOptions }) {
1060
1068
  const base = {
1061
1069
  ok: true,
@@ -1238,11 +1246,11 @@ async function browserRequest(url, customOptions = {}) {
1238
1246
  const headers = route.request().headers();
1239
1247
 
1240
1248
  route.continue({
1241
- headers: {
1249
+ headers: filterHeaders({
1242
1250
  ...headers,
1243
1251
  ...options.headers,
1244
1252
  cookie: getCookie(options),
1245
- },
1253
+ }, options),
1246
1254
  });
1247
1255
  });
1248
1256
 
@@ -1393,15 +1401,17 @@ async function request(url, body, customOptions = {}, method = 'GET') {
1393
1401
  const curatedBody = curateRequestBody(body);
1394
1402
  const curatedCookie = getCookie(options);
1395
1403
 
1404
+ const headers = filterHeaders({
1405
+ ...curatedBody.headers,
1406
+ ...options.headers,
1407
+ cookie: curatedCookie,
1408
+ }, options);
1409
+
1396
1410
  const res = await limiter.schedule(async () => undici.fetch(url, {
1397
1411
  dispatcher: agent,
1398
1412
  method,
1399
1413
  body: curatedBody.body,
1400
- headers: {
1401
- ...curatedBody.headers,
1402
- ...options.headers,
1403
- cookie: curatedCookie,
1404
- },
1414
+ headers,
1405
1415
  signal: options.abortSignal,
1406
1416
  })).catch((error) => ({ // tends to happen when proxy can't reach host
1407
1417
  status: 500,
package/tests/init.js CHANGED
@@ -37,6 +37,7 @@ async function initTest() {
37
37
  const cookiesRes = await unprint.get(`http://127.0.0.1:${port}/json`, {
38
38
  headers: {
39
39
  cookie: 'foo=bar',
40
+ 'User-Agent': null,
40
41
  },
41
42
  cookies: {
42
43
  hello: 'world',