New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fetch-h2

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-h2 - npm Package Compare versions

Comparing version 2.4.5 to 2.5.0

dist/lib/simple-session.d.ts

23

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CookieJar = exports.TimeoutError = exports.AbortError = exports.Response = exports.Request = exports.Headers = exports.DataBody = exports.StreamBody = exports.JsonBody = exports.Body = exports.AbortController = exports.onPush = exports.disconnectAll = exports.disconnect = exports.fetch = exports.context = exports.setup = void 0;
const abort_1 = require("./lib/abort");
exports.AbortController = abort_1.AbortController;
Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return abort_1.AbortController; } });
const body_1 = require("./lib/body");
exports.Body = body_1.Body;
exports.DataBody = body_1.DataBody;
exports.JsonBody = body_1.JsonBody;
exports.StreamBody = body_1.StreamBody;
Object.defineProperty(exports, "Body", { enumerable: true, get: function () { return body_1.Body; } });
Object.defineProperty(exports, "DataBody", { enumerable: true, get: function () { return body_1.DataBody; } });
Object.defineProperty(exports, "JsonBody", { enumerable: true, get: function () { return body_1.JsonBody; } });
Object.defineProperty(exports, "StreamBody", { enumerable: true, get: function () { return body_1.StreamBody; } });
const context_1 = require("./lib/context");
const cookie_jar_1 = require("./lib/cookie-jar");
exports.CookieJar = cookie_jar_1.CookieJar;
Object.defineProperty(exports, "CookieJar", { enumerable: true, get: function () { return cookie_jar_1.CookieJar; } });
const core_1 = require("./lib/core");
exports.AbortError = core_1.AbortError;
exports.TimeoutError = core_1.TimeoutError;
Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return core_1.AbortError; } });
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return core_1.TimeoutError; } });
const headers_1 = require("./lib/headers");
exports.Headers = headers_1.Headers;
Object.defineProperty(exports, "Headers", { enumerable: true, get: function () { return headers_1.Headers; } });
const request_1 = require("./lib/request");
exports.Request = request_1.Request;
Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_1.Request; } });
const response_1 = require("./lib/response");
exports.Response = response_1.Response;
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
const defaultContext = new context_1.Context();

@@ -23,0 +24,0 @@ const setup = (opts) => defaultContext.setup(opts);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbortController = exports.signalEvent = void 0;
const events_1 = require("events");

@@ -4,0 +5,0 @@ exports.signalEvent = "internal-abort";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BodyInspector = exports.DataBody = exports.StreamBody = exports.JsonBody = exports.Body = void 0;
const crypto_1 = require("crypto");

@@ -140,3 +141,3 @@ const already_1 = require("already");

if (!this._signal)
return get_stream_1.default.buffer(readable);
return get_stream_1.buffer(readable);
// Race the readable against the abort signal

@@ -152,3 +153,3 @@ let callback = () => { };

return await Promise.race([
get_stream_1.default.buffer(readable),
get_stream_1.buffer(readable),
onAborted,

@@ -155,0 +156,0 @@ ]);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.H1Context = exports.OriginPool = void 0;
const http_1 = require("http");

@@ -4,0 +5,0 @@ const https_1 = require("https");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.H2Context = void 0;
const http2_1 = require("http2");

@@ -4,0 +5,0 @@ const url_1 = require("url");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.connectTLS = void 0;
const tls_1 = require("tls");
const san_1 = require("./san");
const needsSocketHack = ["12", "13"]
.includes(process.versions.node.split('.')[0]);
const alpnProtocols = {

@@ -53,2 +56,6 @@ http1: Buffer.from("\x08http/1.1"),

});
if (needsSocketHack)
socket.once('secureConnect', () => {
socket.secureConnecting = false;
});
socket.once("error", reject);

@@ -55,0 +62,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Context = void 0;
const url_1 = require("url");

@@ -80,3 +81,3 @@ const already_1 = require("already");

async fetch(input, init) {
return this.retryFetch(input, init, 0);
return this.retryFetch(input, init);
}

@@ -98,5 +99,5 @@ async disconnect(url) {

}
async retryFetch(input, init, count) {
async retryFetch(input, init, extra, count = 0) {
++count;
return this.retryableFetch(input, init)
return this.retryableFetch(input, init, extra)
.catch(already_1.specific(core_1.RetryError, err => {

@@ -106,6 +107,6 @@ // TODO: Implement a more robust retry logic

throw err;
return this.retryFetch(input, init, count);
return this.retryFetch(input, init, extra, count);
}));
}
async retryableFetch(input, init) {
async retryableFetch(input, init, extra) {
const { hostname, origin, port, protocol, url } = this.parseInput(input);

@@ -125,2 +126,3 @@ // Rewrite url to get rid of "http1://" and "http2://"

userAgent: () => this.userAgent(origin),
newFetch: this.retryFetch.bind(this),
});

@@ -135,3 +137,3 @@ const doFetchHttp1 = (socket, cleanup) => {

};
return fetch_http1_1.fetch(sessionGetterHttp1, request, init);
return fetch_http1_1.fetch(sessionGetterHttp1, request, init, extra);
};

@@ -146,3 +148,3 @@ const doFetchHttp2 = async (cacheableSession) => {

};
return await fetch_http2_1.fetch(sessionGetterHttp2, request, init);
return await fetch_http2_1.fetch(sessionGetterHttp2, request, init, extra);
}

@@ -149,0 +151,0 @@ catch (err) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CookieJar = void 0;
const tough_cookie_1 = require("tough-cookie");

@@ -4,0 +5,0 @@ class CookieJar {

/// <reference types="node" />
import { ClientRequest } from "http";
import { ClientHttp2Session } from "http2";
import { AbortSignal } from "./abort";
import { CookieJar } from "./cookie-jar";
import { Headers, RawHeaders } from "./headers";

@@ -86,22 +83,1 @@ export declare type Method = "ACL" | "BIND" | "CHECKOUT" | "CONNECT" | "COPY" | "DELETE" | "GET" | "HEAD" | "LINK" | "LOCK" | "M-SEARCH" | "MERGE" | "MKACTIVITY" | "MKCALENDAR" | "MKCOL" | "MOVE" | "NOTIFY" | "OPTIONS" | "PATCH" | "POST" | "PROPFIND" | "PROPPATCH" | "PURGE" | "PUT" | "REBIND" | "REPORT" | "SEARCH" | "SUBSCRIBE" | "TRACE" | "UNBIND" | "UNLINK" | "UNLOCK" | "UNSUBSCRIBE";

}
export interface SimpleSession {
protocol: HttpProtocols;
cookieJar: CookieJar;
userAgent(): string;
accept(): string;
contentDecoders(): ReadonlyArray<Decoder>;
}
export interface SimpleSessionHttp1Request {
req: ClientRequest;
cleanup: () => void;
}
export interface SimpleSessionHttp2Session {
session: Promise<ClientHttp2Session>;
cleanup: () => void;
}
export interface SimpleSessionHttp1 extends SimpleSession {
get(url: string): SimpleSessionHttp1Request;
}
export interface SimpleSessionHttp2 extends SimpleSession {
get(): SimpleSessionHttp2Session;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parsePerOrigin = exports.getByOrigin = exports.RetryError = exports.TimeoutError = exports.AbortError = exports.FetchError = void 0;
class FetchError extends Error {

@@ -4,0 +5,0 @@ constructor(message) {

@@ -1,2 +0,3 @@

import { AbortError, Decoder, FetchInit, SimpleSession, TimeoutError } from "./core";
import { AbortError, Decoder, FetchInit, TimeoutError } from "./core";
import { SimpleSession } from "./simple-session";
import { RawHeaders } from "./headers";

@@ -3,0 +4,0 @@ import { Request } from "./request";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeRedirectionMethodError = exports.makeRedirectionError = exports.makeIllegalRedirectError = exports.makeTimeoutError = exports.makeAbortedError = exports.make100Error = exports.handleSignalAndTimeout = exports.setupFetch = void 0;
const http2_1 = require("http2");

@@ -12,3 +13,3 @@ const url_1 = require("url");

// Required for a request
HTTP2_HEADER_METHOD, HTTP2_HEADER_SCHEME, HTTP2_HEADER_PATH,
HTTP2_HEADER_METHOD, HTTP2_HEADER_SCHEME, HTTP2_HEADER_PATH, HTTP2_HEADER_AUTHORITY,
// Methods

@@ -58,3 +59,3 @@ HTTP2_METHOD_GET, HTTP2_METHOD_HEAD,

const { signal, onTrailers } = init;
const { origin, protocol, pathname, search, hash, } = new url_1.URL(url);
const { origin, protocol, host, pathname, search, hash, } = new url_1.URL(url);
const path = pathname + search + hash;

@@ -69,2 +70,4 @@ const endStream = method === HTTP2_METHOD_GET || method === HTTP2_METHOD_HEAD;

cookies.push(...utils_1.arrayify(headers.get(HTTP2_HEADER_COOKIE)));
if (!headers.has("host"))
headers.set("host", host);
const headersToSend = {

@@ -88,3 +91,3 @@ // Set required headers

// https://github.com/grantila/fetch-h2/issues/9
headersToSend[":authority"] = val;
headersToSend[HTTP2_HEADER_AUTHORITY] = val;
else if (key !== HTTP2_HEADER_COOKIE)

@@ -91,0 +94,0 @@ headersToSend[key] = val;

@@ -1,2 +0,3 @@

import { FetchInit, SimpleSessionHttp1 } from "./core";
import { FetchInit } from "./core";
import { SimpleSessionHttp1 } from "./simple-session";
import { FetchExtra } from "./fetch-common";

@@ -6,2 +7,2 @@ import { Request } from "./request";

export declare function fetchImpl(session: SimpleSessionHttp1, input: Request, init: Partial<FetchInit> | undefined, extra: FetchExtra): Promise<Response>;
export declare function fetch(session: SimpleSessionHttp1, input: Request, init?: Partial<FetchInit>): Promise<Response>;
export declare function fetch(session: SimpleSessionHttp1, input: Request, init?: Partial<FetchInit>, extra?: FetchExtra): Promise<Response>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetch = exports.fetchImpl = void 0;
const http2_1 = require("http2");

@@ -99,4 +100,5 @@ const callguard_1 = require("callguard");

}, bodySignal, 1, input.allowForbiddenHeaders, integrity));
const { url: locationUrl, isRelative } = location;
if (redirect === "error")
return reject(fetch_common_1.makeRedirectionError(location));
return reject(fetch_common_1.makeRedirectionError(locationUrl));
// redirect is 'follow'

@@ -107,10 +109,16 @@ // We don't support re-sending a non-GET/HEAD request (as

if (!endStream)
return reject(fetch_common_1.makeRedirectionMethodError(location, method));
if (!location)
return reject(fetch_common_1.makeIllegalRedirectError());
return reject(fetch_common_1.makeRedirectionMethodError(locationUrl, method));
res.destroy();
resolve(fetchImpl(session, request.clone(location), { signal, onTrailers }, {
redirected: redirected.concat(url),
timeoutAt,
}));
if (isRelative) {
resolve(fetchImpl(session, request.clone(locationUrl), { signal, onTrailers }, {
redirected: redirected.concat(url),
timeoutAt,
}));
}
else {
resolve(session.newFetch(request.clone(locationUrl), init, {
timeoutAt,
redirected: redirected.concat(url),
}));
}
}));

@@ -133,5 +141,8 @@ });

exports.fetchImpl = fetchImpl;
function fetch(session, input, init) {
const timeoutAt = void 0;
const extra = { timeoutAt, redirected: [] };
function fetch(session, input, init, extra) {
var _a;
extra = {
timeoutAt: extra === null || extra === void 0 ? void 0 : extra.timeoutAt,
redirected: (_a = extra === null || extra === void 0 ? void 0 : extra.redirected) !== null && _a !== void 0 ? _a : [],
};
return fetchImpl(session, input, init, extra);

@@ -138,0 +149,0 @@ }

@@ -1,4 +0,6 @@

import { FetchInit, SimpleSessionHttp2 } from "./core";
import { FetchInit } from "./core";
import { SimpleSessionHttp2 } from "./simple-session";
import { FetchExtra } from "./fetch-common";
import { Request } from "./request";
import { Response } from "./response";
export declare function fetch(session: SimpleSessionHttp2, input: Request, init?: Partial<FetchInit>): Promise<Response>;
export declare function fetch(session: SimpleSessionHttp2, input: Request, init?: Partial<FetchInit>, extra?: FetchExtra): Promise<Response>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetch = void 0;
const http2_1 = require("http2");

@@ -48,2 +49,3 @@ const callguard_1 = require("callguard");

let stream;
let shouldCleanupSocket = true;
try {

@@ -83,3 +85,4 @@ stream = h2session.request(headersToSend, { endStream });

stream.on("close", guard(() => {
socketCleanup();
if (shouldCleanupSocket)
socketCleanup();
// We'll get an 'error' event if there actually is an

@@ -159,4 +162,5 @@ // error, but not if we got NGHTTP2_NO_ERROR.

: extra.redirected.length > 0, {}, bodySignal, 2, input.allowForbiddenHeaders, integrity));
const { url: locationUrl, isRelative } = location;
if (redirect === "error")
return reject(fetch_common_1.makeRedirectionError(location));
return reject(fetch_common_1.makeRedirectionError(locationUrl));
// redirect is 'follow'

@@ -167,11 +171,20 @@ // We don't support re-sending a non-GET/HEAD request (as

if (!endStream)
return reject(fetch_common_1.makeRedirectionMethodError(location, method));
return reject(fetch_common_1.makeRedirectionMethodError(locationUrl, method));
if (!location)
return reject(fetch_common_1.makeIllegalRedirectError());
stream.destroy();
resolve(fetchImpl(session, request.clone(location), { signal, onTrailers }, {
raceConditionedGoaway,
redirected: redirected.concat(url),
timeoutAt,
}));
if (isRelative) {
shouldCleanupSocket = false;
stream.destroy();
resolve(fetchImpl(session, request.clone(locationUrl), init, {
raceConditionedGoaway,
redirected: redirected.concat(url),
timeoutAt,
}));
}
else {
resolve(session.newFetch(request.clone(locationUrl), init, {
timeoutAt,
redirected: redirected.concat(url),
}));
}
}));

@@ -191,9 +204,12 @@ });

}
function fetch(session, input, init) {
const timeoutAt = void 0;
const raceConditionedGoaway = new Set();
const extra = { timeoutAt, redirected: [], raceConditionedGoaway };
return fetchImpl(session, input, init, extra);
function fetch(session, input, init, extra) {
var _a;
const http2Extra = {
timeoutAt: extra === null || extra === void 0 ? void 0 : extra.timeoutAt,
redirected: (_a = extra === null || extra === void 0 ? void 0 : extra.redirected) !== null && _a !== void 0 ? _a : [],
raceConditionedGoaway: new Set(),
};
return fetchImpl(session, input, init, http2Extra);
}
exports.fetch = fetch;
//# sourceMappingURL=fetch-http2.js.map

@@ -1,1 +0,1 @@

export declare const version = "2.4.5";
export declare const version = "2.5.0";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "2.4.5";
exports.version = void 0;
exports.version = "2.5.0";
//# sourceMappingURL=version.js.map

@@ -19,2 +19,3 @@ export declare type GuardTypes = "immutable" | "request" | "request-no-cors" | "response" | "none";

values(): IterableIterator<string>;
toJSON(): {};
}

@@ -21,0 +22,0 @@ export declare class GuardedHeaders extends Headers {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureHeaders = exports.GuardedHeaders = exports.Headers = void 0;
const utils_1 = require("./utils");

@@ -154,2 +155,7 @@ const forbiddenHeaders = [

}
// This is non-standard, but useful
toJSON() {
return [...this.entries()]
.reduce((prev, [key, val]) => Object.assign(prev, { [key]: val }), {});
}
}

@@ -156,0 +162,0 @@ exports.Headers = Headers;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Request = void 0;
const body_1 = require("./body");

@@ -4,0 +5,0 @@ const headers_1 = require("./headers");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamResponse = exports.Response = void 0;
const http2_1 = require("http2");

@@ -4,0 +5,0 @@ const stream_1 = require("stream");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseOrigin = exports.makeRegex = void 0;
function getNames(cert) {

@@ -4,0 +5,0 @@ var _a, _b;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setDestroyed = exports.isDestroyed = exports.setGotGoaway = exports.hasGotGoaway = void 0;
function hasGotGoaway(session) {

@@ -4,0 +5,0 @@ return !!session.__fetch_h2_goaway;

@@ -5,3 +5,7 @@ /// <reference types="node" />

export declare function arrayify<T>(value: T | Array<T> | Readonly<T> | ReadonlyArray<T> | undefined | null): Array<T>;
export declare function parseLocation(location: string | Array<string> | undefined, origin: string): string | null;
export interface ParsedLocation {
url: string;
isRelative: boolean;
}
export declare function parseLocation(location: string | Array<string> | undefined, origin: string): null | ParsedLocation;
export declare const isRedirectStatus: {

@@ -8,0 +12,0 @@ [status: string]: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasBuiltinBrotli = exports.uniq = exports.identity = exports.parseInput = exports.makeOkError = exports.isRedirectStatus = exports.parseLocation = exports.arrayify = exports.pipeline = void 0;
const url_1 = require("url");

@@ -21,4 +22,8 @@ const zlib_1 = require("zlib");

return null;
const originUrl = new url_1.URL(origin);
const url = new url_1.URL(location, origin);
return url.href;
return {
url: url.href,
isRelative: originUrl.origin === url.origin,
};
}

@@ -25,0 +30,0 @@ exports.parseLocation = parseLocation;

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

method: method,
redirect: 'follow',
});

@@ -25,0 +26,0 @@ stream_1.pipeline(await response.readable(), process.stdout, err => {

@@ -355,3 +355,3 @@ "use strict";

const body = new index_1.DataBody(null);
const data = await get_stream_1.default.buffer(await body.readable());
const data = await get_stream_1.buffer(await body.readable());
expect(data.toString()).toBe("");

@@ -361,3 +361,3 @@ });

const body = new index_1.DataBody("foo");
const data = await get_stream_1.default.buffer(await body.readable());
const data = await get_stream_1.buffer(await body.readable());
expect(data.toString()).toBe("foo");

@@ -367,3 +367,3 @@ });

const body = new index_1.DataBody(Buffer.from("foo"));
const data = await get_stream_1.default.buffer(await body.readable());
const data = await get_stream_1.buffer(await body.readable());
expect(data.toString()).toBe("foo");

@@ -375,3 +375,3 @@ });

const body = new index_1.StreamBody(stream);
const data = await get_stream_1.default.buffer(await body.readable());
const data = await get_stream_1.buffer(await body.readable());
expect(data.toString()).toBe("foo");

@@ -378,0 +378,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const already_1 = require("already");
const server_helpers_1 = require("../lib/server-helpers");

@@ -82,3 +83,3 @@ const index_1 = require("../../index");

}
disconnectAll();
await disconnectAll();
await server.shutdown();

@@ -97,3 +98,3 @@ });

expect(res["user-agent"]).toBe("foobar");
disconnectAll();
await disconnectAll();
await server.shutdown();

@@ -164,3 +165,3 @@ });

const { server } = await makeServer();
const { disconnectAll, fetch } = index_1.context();
const { disconnectAll, fetch } = index_1.context({ ...cycleOpts });
const awaitFetch = fetch("${proto}//localhost:0");

@@ -185,4 +186,52 @@ disconnectAll();

});
describe("session sharing", () => {
jest.setTimeout(2500);
it("should re-use session for same host", async () => {
const { disconnectAll, fetch } = index_1.context({ ...cycleOpts });
const urls = [
["https://en.wikipedia.org/wiki/33", "33"],
["https://en.wikipedia.org/wiki/44", "44"],
["https://en.wikipedia.org/wiki/42", "42"],
];
const resps = await already_1.map(urls, { concurrency: Infinity }, async ([url, title]) => {
const resp = await fetch(url);
const text = await resp.text();
const m = text.match(/<h1[^>]*>(.*)<\/h1>/);
return { expected: title, got: m === null || m === void 0 ? void 0 : m[1] };
});
resps.forEach(({ expected, got }) => {
expect(expected).toBe(got);
});
await disconnectAll();
});
it("should re-use session for same SAN but different host", async () => {
const { disconnectAll, fetch } = index_1.context({ ...cycleOpts });
const urls = [
{ lang: "en", title: "33" },
{ lang: "en", title: "44" },
{ lang: "sv", title: "33" },
{ lang: "sv", title: "44" },
];
const resps = await already_1.map(urls, { concurrency: Infinity }, async ({ lang, title }) => {
const url = `https://${lang}.wikipedia.org/wiki/${title}`;
const resp = await fetch(url);
const text = await resp.text();
const mLang = text.match(/<html[^>]* lang="([^"]+)"/);
const mTitle = text.match(/<h1[^>]*>([^<]+)<\/h1>/);
return {
expectedLang: lang,
gotLang: mLang === null || mLang === void 0 ? void 0 : mLang[1],
expectedTitle: title,
gotTitle: mTitle === null || mTitle === void 0 ? void 0 : mTitle[1],
};
});
resps.forEach(({ expectedLang, gotLang, expectedTitle, gotTitle }) => {
expect(expectedLang).toBe(gotLang);
expect(expectedTitle).toBe(gotTitle);
});
await disconnectAll();
});
});
});
});
//# sourceMappingURL=context.js.map

@@ -26,4 +26,21 @@ "use strict";

});
it(`should handle redirect ${proto} ${version}`, async () => {
const { port, server } = await makeServer();
const url = `${proto}//localhost:${port}/redirect/delay/50`;
const body = { foo: "bar" };
const { stdout } = await execa(script, ["GET", url, version, "insecure"], { input: JSON.stringify(body), stderr: 'inherit' });
expect(stdout).toBe("abcdefghij");
await server.shutdown();
});
it(`should handle absolute redirect ${proto} ${version}`, async () => {
const { port, server } = await makeServer();
const redirectTo = `${proto}//localhost:${port}/delay/50`;
const url = `${proto}//localhost:${port}/redirect/${redirectTo}`;
const body = { foo: "bar" };
const { stdout } = await execa(script, ["GET", url, version, "insecure"], { input: JSON.stringify(body), stderr: 'inherit' });
expect(stdout).toBe("abcdefghij");
await server.shutdown();
});
});
});
//# sourceMappingURL=event-loop-reference.js.map

@@ -343,3 +343,3 @@ "use strict";

const stream = await response.readable();
const data = await get_stream_1.default.buffer(stream);
const data = await get_stream_1.buffer(stream);
expect(JSON.parse(data.toString())).toEqual(testData);

@@ -357,3 +357,3 @@ await server.shutdown();

const stream = await response.readable();
const data = await get_stream_1.default.buffer(stream);
const data = await get_stream_1.buffer(stream);
expect(JSON.parse(data.toString())).toEqual(testData);

@@ -373,3 +373,3 @@ await server.shutdown();

const stream = await response.readable();
const data = await get_stream_1.default.buffer(stream);
const data = await get_stream_1.buffer(stream);
expect(JSON.parse(data.toString())).toEqual(testData);

@@ -419,3 +419,3 @@ await server.shutdown();

});
it("user-disconnect closes all sessions", async () => {
it.skip("user-disconnect closes all sessions", async () => {
const { server, port } = await makeServer();

@@ -479,4 +479,4 @@ const url1 = `${proto}//localhost:${port}/goaway/50`;

? "socket hang up"
: "Stream prematurely closed";
expect(err.message).toContain(expected);
: ["Stream prematurely closed", "Connection closed"];
expect(expected).toContain(err.message);
}

@@ -483,0 +483,0 @@ await disconnectAll();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypedServer = exports.Server = exports.ignoreError = void 0;
exports.ignoreError = (cb) => { try {

@@ -4,0 +5,0 @@ cb();

@@ -8,4 +8,4 @@ import { ServerOptions, TestData } from "./server-common";

cycleOpts: {
httpProtocol: import("../..").HttpProtocols;
httpsProtocols: import("../..").HttpProtocols[];
httpProtocol: "http2" | "http1";
httpsProtocols: ("http2" | "http1")[];
session: {

@@ -12,0 +12,0 @@ rejectUnauthorized: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeMakeServer = void 0;
const fs_1 = require("fs");

@@ -4,0 +5,0 @@ const path = require("path");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeServer = exports.ServerHttp1 = void 0;
const http_1 = require("http");

@@ -13,3 +14,3 @@ const http2_1 = require("http2");

// These are the same in HTTP/1 and HTTP/2
const { HTTP2_HEADER_ACCEPT_ENCODING, HTTP2_HEADER_CONTENT_LENGTH, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_SET_COOKIE, } = http2_1.constants;
const { HTTP2_HEADER_ACCEPT_ENCODING, HTTP2_HEADER_CONTENT_LENGTH, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_SET_COOKIE, HTTP2_HEADER_LOCATION, } = http2_1.constants;
class ServerHttp1 extends server_common_1.TypedServer {

@@ -76,3 +77,3 @@ constructor(opts) {

};
const data = await get_stream_1.default.buffer(request);
const data = await get_stream_1.buffer(request);
const json = JSON.parse(data.toString());

@@ -112,3 +113,3 @@ json.forEach((cookie) => {

};
const data = await get_stream_1.default.buffer(request);
const data = await get_stream_1.buffer(request);
const json = JSON.parse(data.toString());

@@ -188,2 +189,13 @@ sendHeaders(responseHeaders);

}
else if (path.startsWith("/redirect/")) {
const redirectTo = path.slice(10).startsWith("http")
? path.slice(10)
: path.slice(9);
const responseHeaders = {
":status": 302,
[HTTP2_HEADER_LOCATION]: redirectTo,
};
sendHeaders(responseHeaders);
response.end();
}
else {

@@ -190,0 +202,0 @@ response.end();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeServer = exports.ServerHttp2 = void 0;
const http2_1 = require("http2");

@@ -10,3 +11,3 @@ const utils_1 = require("../../lib/utils");

const server_common_1 = require("./server-common");
const { HTTP2_HEADER_PATH, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_CONTENT_LENGTH, HTTP2_HEADER_ACCEPT_ENCODING, HTTP2_HEADER_SET_COOKIE, } = http2_1.constants;
const { HTTP2_HEADER_PATH, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_CONTENT_LENGTH, HTTP2_HEADER_ACCEPT_ENCODING, HTTP2_HEADER_SET_COOKIE, HTTP2_HEADER_LOCATION, } = http2_1.constants;
class ServerHttp2 extends server_common_1.TypedServer {

@@ -72,3 +73,3 @@ constructor(opts) {

};
const data = await get_stream_1.default.buffer(stream);
const data = await get_stream_1.buffer(stream);
const json = JSON.parse(data.toString());

@@ -106,3 +107,3 @@ json.forEach((cookie) => {

};
const data = await get_stream_1.default.buffer(stream);
const data = await get_stream_1.buffer(stream);
const json = JSON.parse(data.toString());

@@ -140,3 +141,3 @@ stream.once("wantTrailers", () => {

};
const data = await get_stream_1.default.buffer(stream);
const data = await get_stream_1.buffer(stream);
const json = JSON.parse(data.toString());

@@ -226,2 +227,13 @@ json.forEach((pushable) => {

}
else if (path.startsWith("/redirect/")) {
const redirectTo = path.slice(10).startsWith("http")
? path.slice(10)
: path.slice(9);
const responseHeaders = {
":status": 302,
[HTTP2_HEADER_LOCATION]: redirectTo,
};
stream.respond(responseHeaders);
stream.end();
}
else {

@@ -228,0 +240,0 @@ const matched = (this._opts.matchers || [])

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureStatusSuccess = exports.cleanUrl = exports.createIntegrity = void 0;
const crypto_1 = require("crypto");

@@ -4,0 +5,0 @@ function createIntegrity(data, hashType = "sha256") {

{
"name": "fetch-h2",
"version": "2.4.5",
"version": "2.5.0",
"description": "HTTP/1+2 Fetch API client for Node.js",

@@ -55,27 +55,27 @@ "author": "Gustaf Räntilä",

"@types/from2": "^2.3.0",
"@types/jest": "^25.1.4",
"@types/node": "^13.9.1",
"@types/through2": "^2.0.34",
"commitizen": "^4.0.3",
"@types/jest": "^25.2.3",
"@types/node": "^14.6.0",
"@types/through2": "^2.0.36",
"commitizen": "^4.1.2",
"compd": "^1.3.7",
"concurrently": "^5.1.0",
"cz-conventional-changelog": "^3.1.0",
"execa": "^4.0.0",
"concurrently": "^5.3.0",
"cz-conventional-changelog": "^3.2.0",
"execa": "^4.0.3",
"from2": "^2.3.0",
"jest": "^25.1.0",
"mkcert": "^1.2.0",
"mkcert": "^1.3.0",
"rimraf": "^3.0.2",
"ts-jest": "^25.2.1",
"ts-node": "^8.6.2",
"tslint": "^6.1.0",
"typescript": "^3.8.3"
"ts-node": "^8.10.2",
"tslint": "^6.1.3",
"typescript": "^3.9.7"
},
"dependencies": {
"@types/tough-cookie": "^2.3.6",
"already": "^1.12.0",
"@types/tough-cookie": "^4.0.0",
"already": "^1.13.1",
"callguard": "^1.2.1",
"get-stream": "^5.1.0",
"through2": "^3.0.1",
"get-stream": "^6.0.0",
"through2": "^4.0.2",
"to-arraybuffer": "^1.0.1",
"tough-cookie": "^3.0.1"
"tough-cookie": "^4.0.0"
},

@@ -82,0 +82,0 @@ "config": {

@@ -170,2 +170,3 @@ [![npm version][npm-image]][npm-url]

* The response object has an extra property `httpVersion` which is either `1` or `2` (numbers), depending on what was negotiated with the server.
* The `Headers` class (e.g. retried by `{response}.headers`) has a `toJSON` function which converts the headers to a simple JavaScript object.

@@ -172,0 +173,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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