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

@osskit/fetch-enhancers

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@osskit/fetch-enhancers - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

3

dist/src/enhancers/withHeaders.d.ts
import type { Fetch } from '../types';
export declare const withHeaders: (fetch: Fetch, getHeaders: () => Record<string, string>) => Fetch;
import { Headers } from 'node-fetch';
export declare const withHeaders: (fetch: Fetch, getHeaders: (headers?: Headers | undefined) => Record<string, string>) => Fetch;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withHeaders = void 0;
const node_fetch_1 = require("node-fetch");
const withHeaders = (fetch, getHeaders) => (url, init) => fetch(url, {

@@ -8,3 +9,3 @@ ...init,

...init?.headers,
...getHeaders(),
...getHeaders(new node_fetch_1.Headers(init?.headers)),
},

@@ -11,0 +12,0 @@ });

@@ -31,2 +31,24 @@ "use strict";

});
const fetchWithExtraHeaders = (0, src_1.withHeaders)(node_fetch_1.default, (headers) => ({ ...headers, foo: 'bar', id: 'override' }));
test('add headers', async () => {
const server = (0, http_1.createServer)((req, res) => {
const response = req.headers['id'];
res.writeHead(200);
res.end(response);
});
return new Promise((resolve, reject) => {
server.listen(async () => {
const { port } = server.address();
try {
const res = await fetchWithExtraHeaders(`http://127.0.0.1:${port}`, { headers: { id: 'id' } });
expect(await res.text()).toBe('override');
resolve();
}
finally {
server.close();
}
});
server.on('error', reject);
});
});
//# sourceMappingURL=withHeaders.spec.js.map
{
"name": "@osskit/fetch-enhancers",
"version": "2.1.0",
"version": "2.2.0",
"repository": {

@@ -5,0 +5,0 @@ "url": "https://github.com/osskit/fetch-enhancers"

import type { RequestInfo, RequestInit } from 'node-fetch';
import type { Fetch } from '../types';
import { Headers } from 'node-fetch';
export const withHeaders =
(fetch: Fetch, getHeaders: () => Record<string, string>): Fetch =>
(fetch: Fetch, getHeaders: (headers?: Headers) => Record<string, string>): Fetch =>
(url: RequestInfo, init?: RequestInit) =>

@@ -12,4 +13,4 @@ fetch(url, {

...init?.headers,
...getHeaders(),
...getHeaders(new Headers(init?.headers)),
},
});

@@ -31,1 +31,26 @@ import { createServer } from 'http';

});
const fetchWithExtraHeaders = withHeaders(fetch, (headers) => ({ ...headers, foo: 'bar', id: 'override' }));
test('add headers', async () => {
const server = createServer((req, res) => {
const response = req.headers['id'];
res.writeHead(200);
res.end(response);
});
return new Promise<void>((resolve, reject) => {
server.listen(async () => {
const { port } = server.address() as AddressInfo;
try {
const res = await fetchWithExtraHeaders(`http://127.0.0.1:${port}`, { headers: { id: 'id' } });
expect(await res.text()).toBe('override');
resolve();
} finally {
server.close();
}
});
server.on('error', reject);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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