Comparing version 2.1.1 to 2.2.0
@@ -0,1 +1,2 @@ | ||
import { AbortController, AbortSignal } from "./lib/abort"; | ||
import { Body, DataBody, JsonBody, StreamBody } from "./lib/body"; | ||
@@ -21,2 +22,2 @@ import { ContextOptions } from "./lib/context"; | ||
}; | ||
export { setup, context, fetch, disconnect, disconnectAll, onPush, HttpProtocols, Body, JsonBody, StreamBody, DataBody, Headers, Request, Response, AbortError, TimeoutError, OnTrailers, ContextOptions, DecodeFunction, Decoder, CookieJar, }; | ||
export { setup, context, fetch, disconnect, disconnectAll, onPush, AbortController, AbortSignal, HttpProtocols, Body, JsonBody, StreamBody, DataBody, Headers, Request, Response, AbortError, TimeoutError, OnTrailers, ContextOptions, DecodeFunction, Decoder, CookieJar, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const abort_1 = require("./lib/abort"); | ||
exports.AbortController = abort_1.AbortController; | ||
const body_1 = require("./lib/body"); | ||
@@ -4,0 +6,0 @@ exports.Body = body_1.Body; |
/// <reference types="node" /> | ||
import { AbortSignal } from "./abort"; | ||
import { BodyTypes, IBody } from "./core"; | ||
@@ -10,2 +11,3 @@ export declare class Body implements IBody { | ||
private _integrity?; | ||
private _signal?; | ||
constructor(); | ||
@@ -17,5 +19,7 @@ arrayBuffer(allowIncomplete?: boolean): Promise<ArrayBuffer>; | ||
readable(): Promise<NodeJS.ReadableStream>; | ||
protected setSignal(signal: AbortSignal | undefined): void; | ||
protected hasBody(): boolean; | ||
protected setBody(body: BodyTypes | IBody | null, mime?: string | null, integrity?: string | null, length?: number | null): void; | ||
private validateIntegrity; | ||
private _ensureNotAborted; | ||
private _ensureUnused; | ||
@@ -22,0 +26,0 @@ private blob; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const toArrayBuffer = require("to-arraybuffer"); | ||
const core_1 = require("./core"); | ||
function makeUnknownDataError() { | ||
@@ -40,2 +41,3 @@ return new Error("Unknown body data"); | ||
this._ensureUnused(); | ||
this._ensureNotAborted(); | ||
if (this._body == null) | ||
@@ -57,2 +59,3 @@ return this.validateIntegrity(emptyBuffer, allowIncomplete); | ||
this._ensureUnused(); | ||
this._ensureNotAborted(); | ||
if (this._body == null) | ||
@@ -74,2 +77,3 @@ return Promise.resolve(this.validateIntegrity(emptyBuffer, false)) | ||
this._ensureUnused(); | ||
this._ensureNotAborted(); | ||
if (this._body == null) | ||
@@ -91,2 +95,3 @@ return Promise.resolve(this.validateIntegrity(emptyBuffer, allowIncomplete)) | ||
this._ensureUnused(); | ||
this._ensureNotAborted(); | ||
if (this._body == null) { | ||
@@ -109,2 +114,5 @@ const stream = through2(); | ||
} | ||
setSignal(signal) { | ||
this._signal = signal; | ||
} | ||
hasBody() { | ||
@@ -136,2 +144,3 @@ return "_body" in this; | ||
validateIntegrity(data, allowIncomplete) { | ||
this._ensureNotAborted(); | ||
if (!allowIncomplete && | ||
@@ -156,2 +165,6 @@ this._length != null && | ||
} | ||
_ensureNotAborted() { | ||
if (this._signal && this._signal.aborted) | ||
throw new core_1.AbortError("Response aborted"); | ||
} | ||
_ensureUnused() { | ||
@@ -158,0 +171,0 @@ if (this._used) |
@@ -87,3 +87,3 @@ "use strict"; | ||
async disconnectSocket(socket) { | ||
await new Promise((resolve) => socket.end(Buffer.from([]), () => resolve)); | ||
socket.destroy(); | ||
} | ||
@@ -104,3 +104,3 @@ makeCleaner(socket) { | ||
this.usedSockets.delete(socket); | ||
if (this.maxFreeSockets >= this.unusedSockets.size + 1) { | ||
if (this.maxFreeSockets < this.unusedSockets.size + 1) { | ||
await this.disconnectSocket(socket); | ||
@@ -122,3 +122,3 @@ return; | ||
this.pools = new Map(); | ||
this.keepAlive = core_1.parsePerOrigin(options.keepAlive, false); | ||
this.keepAlive = core_1.parsePerOrigin(options.keepAlive, true); | ||
this.keepAliveMsecs = core_1.parsePerOrigin(options.keepAliveMsecs, 1000); | ||
@@ -189,2 +189,7 @@ this.maxSockets = core_1.parsePerOrigin(options.maxSockets, 256); | ||
}; | ||
if (!options.headers) | ||
options.headers = {}; | ||
options.headers.connection = this.contextPool.keepAlive | ||
? "keep-alive" | ||
: "close"; | ||
return this.contextPool.getOriginPool(origin).connect(options); | ||
@@ -191,0 +196,0 @@ } |
@@ -185,3 +185,3 @@ "use strict"; | ||
pushedStream.once("push", guard((responseHeaders) => { | ||
const response = new response_1.StreamResponse(this._getDecoders(origin), path, pushedStream, responseHeaders, false, {}, 2, false); | ||
const response = new response_1.StreamResponse(this._getDecoders(origin), path, pushedStream, responseHeaders, false, {}, void 0, 2, false); | ||
resolve(response); | ||
@@ -188,0 +188,0 @@ })); |
/// <reference types="node" /> | ||
import { ClientRequest } from "http"; | ||
import { ClientHttp2Session } from "http2"; | ||
import { AbortSignal } from "./abort"; | ||
import { CookieJar } from "./cookie-jar"; | ||
@@ -27,6 +28,2 @@ import { Headers, RawHeaders } from "./headers"; | ||
} | ||
export interface Signal { | ||
readonly aborted: boolean; | ||
onabort: () => void; | ||
} | ||
export interface RequestInitWithoutBody { | ||
@@ -53,3 +50,3 @@ method: Method; | ||
export interface FetchInit extends RequestInit { | ||
signal: Signal; | ||
signal: AbortSignal; | ||
timeout: number; | ||
@@ -56,0 +53,0 @@ onTrailers: OnTrailers; |
@@ -25,3 +25,3 @@ import { AbortError, Decoder, FetchInit, SimpleSession, TimeoutError } from "./core"; | ||
request: Request; | ||
signal: import("./core").Signal | undefined; | ||
signal: import("./abort").AbortSignal | undefined; | ||
signalPromise: Promise<Response> | null; | ||
@@ -28,0 +28,0 @@ timeoutAt: number | undefined; |
@@ -133,8 +133,9 @@ "use strict"; | ||
throw abortError(); | ||
let abortHandler; | ||
const signalPromise = signal | ||
? | ||
new Promise((_resolve, reject) => { | ||
signal.onabort = () => { | ||
signal.once("abort", abortHandler = () => { | ||
reject(abortError()); | ||
}; | ||
}); | ||
}) | ||
@@ -145,4 +146,4 @@ : null; | ||
timeoutInfo.clear(); | ||
if (signal) | ||
delete signal.onabort; | ||
if (signal && abortHandler) | ||
signal.removeListener("abort", abortHandler); | ||
} | ||
@@ -149,0 +150,0 @@ return { |
@@ -5,2 +5,3 @@ "use strict"; | ||
const callguard_1 = require("callguard"); | ||
const abort_1 = require("./abort"); | ||
const fetch_common_1 = require("./fetch-common"); | ||
@@ -44,6 +45,18 @@ const headers_1 = require("./headers"); | ||
res.once("end", socketCleanup); | ||
if (signal && signal.aborted) { | ||
// No reason to continue, the request is aborted | ||
req.abort(); | ||
return; | ||
const { signal: bodySignal = void 0, abort: bodyAbort = void 0, } = signal ? new abort_1.AbortController() : {}; | ||
if (signal) { | ||
const abortHandler = () => { | ||
bodyAbort(); | ||
req.abort(); | ||
res.destroy(); | ||
}; | ||
if (signal.aborted) { | ||
// No reason to continue, the request is aborted | ||
abortHandler(); | ||
return; | ||
} | ||
signal.once("abort", abortHandler); | ||
res.once("end", () => { | ||
signal.removeListener("abort", abortHandler); | ||
}); | ||
} | ||
@@ -87,3 +100,3 @@ const { headers, statusCode } = res; | ||
statusText: res.statusMessage, | ||
}, 1, input.allowForbiddenHeaders, integrity)); | ||
}, bodySignal, 1, input.allowForbiddenHeaders, integrity)); | ||
if (redirect === "error") | ||
@@ -90,0 +103,0 @@ return reject(fetch_common_1.makeRedirectionError(location)); |
@@ -5,2 +5,3 @@ "use strict"; | ||
const callguard_1 = require("callguard"); | ||
const abort_1 = require("./abort"); | ||
const core_1 = require("./core"); | ||
@@ -113,6 +114,17 @@ const fetch_common_1 = require("./fetch-common"); | ||
stream.on("response", guard((headers) => { | ||
if (signal && signal.aborted) { | ||
// No reason to continue, the request is aborted | ||
stream.destroy(); | ||
return; | ||
const { signal: bodySignal = void 0, abort: bodyAbort = void 0, } = signal ? new abort_1.AbortController() : {}; | ||
if (signal) { | ||
const abortHandler = () => { | ||
bodyAbort(); | ||
stream.destroy(); | ||
}; | ||
if (signal.aborted) { | ||
// No reason to continue, the request is aborted | ||
abortHandler(); | ||
return; | ||
} | ||
signal.once("abort", abortHandler); | ||
stream.once("close", () => { | ||
signal.removeListener("abort", abortHandler); | ||
}); | ||
} | ||
@@ -135,3 +147,3 @@ const status = "" + headers[HTTP2_HEADER_STATUS]; | ||
? false | ||
: extra.redirected.length > 0, {}, 2, input.allowForbiddenHeaders, integrity)); | ||
: extra.redirected.length > 0, {}, bodySignal, 2, input.allowForbiddenHeaders, integrity)); | ||
if (redirect === "error") | ||
@@ -138,0 +150,0 @@ return reject(fetch_common_1.makeRedirectionError(location)); |
@@ -1,1 +0,1 @@ | ||
export declare const version = "2.1.1"; | ||
export declare const version = "2.2.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = "2.1.1"; | ||
exports.version = "2.2.0"; | ||
//# sourceMappingURL=version.js.map |
/// <reference types="node" /> | ||
import { BodyTypes, Decoder, HttpVersion, ResponseInit, ResponseTypes } from "./core"; | ||
import { AbortSignal } from "./abort"; | ||
import { Headers } from "./headers"; | ||
@@ -10,2 +11,3 @@ import { Body } from "./body"; | ||
integrity: string; | ||
signal: AbortSignal; | ||
type: ResponseTypes; | ||
@@ -30,4 +32,4 @@ url: string; | ||
export declare class StreamResponse extends Response { | ||
constructor(contentDecoders: ReadonlyArray<Decoder>, url: string, stream: NodeJS.ReadableStream, headers: IncomingHttpHeaders, redirected: boolean, init: Partial<ResponseInit>, httpVersion: HttpVersion, allowForbiddenHeaders: boolean, integrity?: string); | ||
constructor(contentDecoders: ReadonlyArray<Decoder>, url: string, stream: NodeJS.ReadableStream, headers: IncomingHttpHeaders, redirected: boolean, init: Partial<ResponseInit>, signal: AbortSignal | undefined, httpVersion: HttpVersion, allowForbiddenHeaders: boolean, integrity?: string); | ||
} | ||
export {}; |
@@ -20,2 +20,3 @@ "use strict"; | ||
const integrity = _extra.integrity || null; | ||
this.setSignal(_extra.signal); | ||
if (body) { | ||
@@ -119,5 +120,5 @@ const contentType = headers.get(HTTP2_HEADER_CONTENT_TYPE); | ||
} | ||
function makeExtra(httpVersion, url, redirected, integrity) { | ||
function makeExtra(httpVersion, url, redirected, signal, integrity) { | ||
const type = "basic"; // TODO: Implement CORS | ||
return { httpVersion, redirected, integrity, type, url }; | ||
return { httpVersion, redirected, integrity, signal, type, url }; | ||
} | ||
@@ -146,3 +147,3 @@ function handleEncoding(contentDecoders, stream, headers) { | ||
class StreamResponse extends Response { | ||
constructor(contentDecoders, url, stream, headers, redirected, init, httpVersion, allowForbiddenHeaders, integrity) { | ||
constructor(contentDecoders, url, stream, headers, redirected, init, signal, httpVersion, allowForbiddenHeaders, integrity) { | ||
super(handleEncoding(contentDecoders, stream, headers), { | ||
@@ -154,3 +155,3 @@ ...init, | ||
: makeInitHttp2(headers, allowForbiddenHeaders)), | ||
}, makeExtra(httpVersion, url, redirected, integrity)); | ||
}, makeExtra(httpVersion, url, redirected, signal, integrity)); | ||
} | ||
@@ -157,0 +158,0 @@ } |
@@ -7,3 +7,3 @@ "use strict"; | ||
const utils_1 = require("../lib/utils"); | ||
const __1 = require("../../"); | ||
const index_1 = require("../../index"); | ||
async function makeSync(fn) { | ||
@@ -21,3 +21,3 @@ try { | ||
} | ||
class IntegrityBody extends __1.Body { | ||
class IntegrityBody extends index_1.Body { | ||
constructor(data, hashData, integrityHashType = "sha256") { | ||
@@ -34,3 +34,3 @@ super(); | ||
it("throw on multiple reads", async () => { | ||
const body = new __1.DataBody("foo"); | ||
const body = new index_1.DataBody("foo"); | ||
expect(body.bodyUsed).toBe(false); | ||
@@ -45,3 +45,3 @@ expect(await body.text()).toBe("foo"); | ||
it("throw on unimplemented blob()", async () => { | ||
const body = new __1.DataBody("foo"); | ||
const body = new index_1.DataBody("foo"); | ||
expect(await makeSync(() => body.blob())) | ||
@@ -51,3 +51,3 @@ .toThrow(); | ||
it("throw on unimplemented formData()", async () => { | ||
const body = new __1.DataBody("foo"); | ||
const body = new index_1.DataBody("foo"); | ||
expect(await makeSync(() => body.formData())).toThrow(); | ||
@@ -58,3 +58,3 @@ }); | ||
it("handle invalid body type when reading as arrayBuffer", async () => { | ||
const body = new __1.DataBody(1); | ||
const body = new index_1.DataBody(1); | ||
expect(await makeSync(() => body.arrayBuffer())) | ||
@@ -64,3 +64,3 @@ .toThrow("Unknown body data"); | ||
it("handle invalid body type when reading as json", async () => { | ||
const body = new __1.DataBody(1); | ||
const body = new index_1.DataBody(1); | ||
expect(await makeSync(() => body.json())) | ||
@@ -70,3 +70,3 @@ .toThrow("Unknown body data"); | ||
it("handle invalid body type when reading as text", async () => { | ||
const body = new __1.DataBody(1); | ||
const body = new index_1.DataBody(1); | ||
expect(await makeSync(() => body.text())) | ||
@@ -76,3 +76,3 @@ .toThrow("Unknown body data"); | ||
it("handle invalid body type when reading as readable", async () => { | ||
const body = new __1.DataBody(1); | ||
const body = new index_1.DataBody(1); | ||
expect(await makeSync(() => body.readable())) | ||
@@ -85,3 +85,3 @@ .toThrow("Unknown body data"); | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
const data = Buffer.from(await body.arrayBuffer()); | ||
@@ -91,3 +91,3 @@ expect(data.toString()).toBe(""); | ||
it("handle string", async () => { | ||
const body = new __1.DataBody("foo"); | ||
const body = new index_1.DataBody("foo"); | ||
const data = Buffer.from(await body.arrayBuffer()); | ||
@@ -97,3 +97,3 @@ expect(data.toString()).toBe("foo"); | ||
it("handle buffer", async () => { | ||
const body = new __1.DataBody(Buffer.from("foo")); | ||
const body = new index_1.DataBody(Buffer.from("foo")); | ||
const data = Buffer.from(await body.arrayBuffer()); | ||
@@ -103,3 +103,3 @@ expect(data.toString()).toBe("foo"); | ||
it("handle JsonBody", async () => { | ||
const body = new __1.JsonBody({ foo: "bar" }); | ||
const body = new index_1.JsonBody({ foo: "bar" }); | ||
const data = Buffer.from(await body.arrayBuffer()); | ||
@@ -111,3 +111,3 @@ expect(data.toString()).toBe('{"foo":"bar"}'); | ||
stream.end("foo"); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
const data = Buffer.from(await body.arrayBuffer()); | ||
@@ -180,23 +180,23 @@ expect(data.toString()).toBe("foo"); | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
expect(await body.json()).toBe(null); | ||
}); | ||
it("handle invalid string", async () => { | ||
const body = new __1.DataBody("invalid json"); | ||
const body = new index_1.DataBody("invalid json"); | ||
expect(await makeSync(() => body.json())).toThrow(); | ||
}); | ||
it("handle valid string", async () => { | ||
const body = new __1.DataBody('{"foo":"bar"}'); | ||
const body = new index_1.DataBody('{"foo":"bar"}'); | ||
expect(await body.json()).toEqual({ foo: "bar" }); | ||
}); | ||
it("handle invalid buffer", async () => { | ||
const body = new __1.DataBody(Buffer.from("invalid json")); | ||
const body = new index_1.DataBody(Buffer.from("invalid json")); | ||
expect(await makeSync(() => body.json())).toThrow(); | ||
}); | ||
it("handle valid buffer", async () => { | ||
const body = new __1.DataBody(Buffer.from('{"foo":"bar"}')); | ||
const body = new index_1.DataBody(Buffer.from('{"foo":"bar"}')); | ||
expect(await body.json()).toEqual({ foo: "bar" }); | ||
}); | ||
it("handle valid JsonBody", async () => { | ||
const body = new __1.JsonBody({ foo: "bar" }); | ||
const body = new index_1.JsonBody({ foo: "bar" }); | ||
expect(await body.json()).toEqual({ foo: "bar" }); | ||
@@ -207,3 +207,3 @@ }); | ||
stream.end("invalid json"); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
expect(await makeSync(() => body.json())).toThrow(); | ||
@@ -214,3 +214,3 @@ }); | ||
stream.end('{"foo":"bar"}'); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
expect(await body.json()).toEqual({ foo: "bar" }); | ||
@@ -221,3 +221,3 @@ }); | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
setHash(body, ""); | ||
@@ -228,3 +228,3 @@ expect(await body.json()).toBe(null); | ||
const testData = '{"foo":"bar"}'; | ||
const body = new __1.DataBody(testData); | ||
const body = new index_1.DataBody(testData); | ||
setHash(body, testData); | ||
@@ -235,3 +235,3 @@ expect(await body.json()).toEqual({ foo: "bar" }); | ||
const testData = '{"foo":"bar"}'; | ||
const body = new __1.DataBody(Buffer.from(testData)); | ||
const body = new index_1.DataBody(Buffer.from(testData)); | ||
setHash(body, testData); | ||
@@ -241,3 +241,3 @@ expect(await body.json()).toEqual({ foo: "bar" }); | ||
it("handle JsonBody", async () => { | ||
const body = new __1.JsonBody({ foo: "bar" }); | ||
const body = new index_1.JsonBody({ foo: "bar" }); | ||
setHash(body, '{"foo":"bar"}'); | ||
@@ -250,3 +250,3 @@ expect(await body.json()).toEqual({ foo: "bar" }); | ||
stream.end(testData); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
setHash(body, testData); | ||
@@ -258,3 +258,3 @@ expect(await body.json()).toEqual({ foo: "bar" }); | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
setHash(body, "" + "x"); | ||
@@ -266,3 +266,3 @@ expect(await makeSync(() => body.json())) | ||
const testData = '{"foo":"bar"}'; | ||
const body = new __1.DataBody(testData); | ||
const body = new index_1.DataBody(testData); | ||
setHash(body, testData + "x"); | ||
@@ -274,3 +274,3 @@ expect(await makeSync(() => body.json())) | ||
const testData = '{"foo":"bar"}'; | ||
const body = new __1.DataBody(Buffer.from(testData)); | ||
const body = new index_1.DataBody(Buffer.from(testData)); | ||
setHash(body, testData + "x"); | ||
@@ -281,3 +281,3 @@ expect(await makeSync(() => body.json())) | ||
it("handle JsonBody", async () => { | ||
const body = new __1.JsonBody({ foo: "bar" }); | ||
const body = new index_1.JsonBody({ foo: "bar" }); | ||
setHash(body, '{"foo":"bar"}' + "x"); | ||
@@ -291,3 +291,3 @@ expect(await makeSync(() => body.json())) | ||
stream.end(testData); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
setHash(body, testData + "x"); | ||
@@ -302,11 +302,11 @@ expect(await makeSync(() => body.json())) | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
expect(await body.text()).toBe(null); | ||
}); | ||
it("handle string", async () => { | ||
const body = new __1.DataBody("foo"); | ||
const body = new index_1.DataBody("foo"); | ||
expect(await body.text()).toBe("foo"); | ||
}); | ||
it("handle buffer", async () => { | ||
const body = new __1.DataBody(Buffer.from("foo")); | ||
const body = new index_1.DataBody(Buffer.from("foo")); | ||
expect(await body.text()).toBe("foo"); | ||
@@ -317,3 +317,3 @@ }); | ||
stream.end("foo"); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
expect(await body.text()).toBe("foo"); | ||
@@ -324,3 +324,3 @@ }); | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
setHash(body, ""); | ||
@@ -331,3 +331,3 @@ expect(await body.text()).toBe(null); | ||
const testData = "foo"; | ||
const body = new __1.DataBody(testData); | ||
const body = new index_1.DataBody(testData); | ||
setHash(body, testData); | ||
@@ -338,3 +338,3 @@ expect(await body.text()).toBe(testData); | ||
const testData = "foo"; | ||
const body = new __1.DataBody(Buffer.from(testData)); | ||
const body = new index_1.DataBody(Buffer.from(testData)); | ||
setHash(body, testData); | ||
@@ -347,3 +347,3 @@ expect(await body.text()).toBe(testData); | ||
stream.end(testData); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
setHash(body, testData); | ||
@@ -355,3 +355,3 @@ expect(await body.text()).toBe(testData); | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
setHash(body, "" + "x"); | ||
@@ -363,3 +363,3 @@ expect(await makeSync(() => body.text())) | ||
const testData = "foo"; | ||
const body = new __1.DataBody(testData); | ||
const body = new index_1.DataBody(testData); | ||
setHash(body, testData + "x"); | ||
@@ -371,3 +371,3 @@ expect(await makeSync(() => body.text())) | ||
const testData = "foo"; | ||
const body = new __1.DataBody(Buffer.from(testData)); | ||
const body = new index_1.DataBody(Buffer.from(testData)); | ||
setHash(body, testData + "x"); | ||
@@ -381,3 +381,3 @@ expect(await makeSync(() => body.text())) | ||
stream.end(testData); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
setHash(body, testData + "x"); | ||
@@ -391,3 +391,3 @@ expect(await makeSync(() => body.text())) | ||
it("handle null", async () => { | ||
const body = new __1.DataBody(null); | ||
const body = new index_1.DataBody(null); | ||
const data = await get_stream_1.default.buffer(await body.readable()); | ||
@@ -397,3 +397,3 @@ expect(data.toString()).toBe(""); | ||
it("handle string", async () => { | ||
const body = new __1.DataBody("foo"); | ||
const body = new index_1.DataBody("foo"); | ||
const data = await get_stream_1.default.buffer(await body.readable()); | ||
@@ -403,3 +403,3 @@ expect(data.toString()).toBe("foo"); | ||
it("handle buffer", async () => { | ||
const body = new __1.DataBody(Buffer.from("foo")); | ||
const body = new index_1.DataBody(Buffer.from("foo")); | ||
const data = await get_stream_1.default.buffer(await body.readable()); | ||
@@ -411,3 +411,3 @@ expect(data.toString()).toBe("foo"); | ||
stream.end("foo"); | ||
const body = new __1.StreamBody(stream); | ||
const body = new index_1.StreamBody(stream); | ||
const data = await get_stream_1.default.buffer(await body.readable()); | ||
@@ -414,0 +414,0 @@ expect(data.toString()).toBe("foo"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const server_helpers_1 = require("../lib/server-helpers"); | ||
const __1 = require("../../"); | ||
const index_1 = require("../../index"); | ||
function ensureStatusSuccess(response) { | ||
@@ -23,3 +23,3 @@ if (response.status < 200 || response.status >= 300) | ||
const { server, port } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -37,3 +37,3 @@ overwriteUserAgent: true, | ||
const { server, port } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -52,3 +52,3 @@ userAgent: "foobar", | ||
const accept = "application/foobar, text/*;0.9"; | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -68,3 +68,3 @@ accept, | ||
const { server, port } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -91,3 +91,3 @@ overwriteUserAgent: true, | ||
const { server, port } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -108,5 +108,5 @@ overwriteUserAgent: true, | ||
const { server, port } = await makeServer(); | ||
const cookieJar = new __1.CookieJar(); | ||
const cookieJar = new index_1.CookieJar(); | ||
expect(await cookieJar.getCookies(`${proto}//localhost:${port}/`)).toEqual([]); | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -142,3 +142,3 @@ cookieJar, | ||
const { server, port } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ ...cycleOpts }); | ||
const { disconnectAll, fetch } = index_1.context({ ...cycleOpts }); | ||
const response = await fetch(`${proto}//localhost:${port}/set-cookie`, { | ||
@@ -155,3 +155,3 @@ json: ["a=b", "c=d"], | ||
const { server, port } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ ...cycleOpts }); | ||
const { disconnectAll, fetch } = index_1.context({ ...cycleOpts }); | ||
const response = await fetch(`${proto}//localhost:${port}/set-cookie`, { | ||
@@ -170,3 +170,3 @@ allowForbiddenHeaders: true, | ||
const { server } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context(); | ||
const { disconnectAll, fetch } = index_1.context(); | ||
const awaitFetch = fetch("${proto}//localhost:0"); | ||
@@ -180,3 +180,3 @@ disconnectAll(); | ||
const { server } = await makeServer(); | ||
const { disconnectAll, fetch } = __1.context({ | ||
const { disconnectAll, fetch } = index_1.context({ | ||
...cycleOpts, | ||
@@ -183,0 +183,0 @@ session: { port: -1, host: {} }, |
@@ -6,3 +6,3 @@ "use strict"; | ||
const through2 = require("through2"); | ||
const __1 = require("../../"); | ||
const index_1 = require("../../index"); | ||
[ | ||
@@ -19,15 +19,19 @@ { protocol: "https:", site: "nghttp2.org/httpbin", protos: ["http2"] }, | ||
jest.setTimeout(5000); | ||
const { fetch, disconnectAll } = __1.context({ | ||
httpsProtocols: protos, | ||
}); | ||
afterEach(disconnectAll); | ||
it("should be possible to GET", async () => { | ||
function wrapContext(fn) { | ||
return async () => { | ||
const { fetch, disconnectAll } = index_1.context({ | ||
httpsProtocols: protos, | ||
}); | ||
await fn(fetch).then(...already_1.Finally(disconnectAll)); | ||
}; | ||
} | ||
it.concurrent("should be possible to GET", wrapContext(async (fetch) => { | ||
const response = await fetch(`${host}/user-agent`); | ||
const data = await response.json(); | ||
expect(data["user-agent"]).toContain("fetch-h2/"); | ||
}); | ||
it("should be possible to POST JSON", async () => { | ||
})); | ||
it.concurrent("should be possible to POST JSON", wrapContext(async (fetch) => { | ||
const testData = { foo: "bar" }; | ||
const response = await fetch(`${host}/post`, { | ||
body: new __1.JsonBody(testData), | ||
body: new index_1.JsonBody(testData), | ||
method: "POST", | ||
@@ -39,7 +43,7 @@ }); | ||
expect(data.headers["Content-Type"]).toBe("application/json"); | ||
}); | ||
it("should be possible to POST buffer-data", async () => { | ||
})); | ||
it.concurrent("should be possible to POST buffer-data", wrapContext(async (fetch) => { | ||
const testData = '{"foo": "data"}'; | ||
const response = await fetch(`${host}/post`, { | ||
body: new __1.DataBody(testData), | ||
body: new index_1.DataBody(testData), | ||
method: "POST", | ||
@@ -50,4 +54,4 @@ }); | ||
expect(data.headers).not.toHaveProperty("Content-Type"); | ||
}); | ||
it("should be possible to POST already ended stream-data", async () => { | ||
})); | ||
it.concurrent("should be possible to POST already ended stream-data", wrapContext(async (fetch) => { | ||
const stream = through2(); | ||
@@ -59,3 +63,3 @@ stream.write("foo"); | ||
allowForbiddenHeaders: true, | ||
body: new __1.StreamBody(stream), | ||
body: new index_1.StreamBody(stream), | ||
headers: { "content-length": "6" }, | ||
@@ -66,8 +70,8 @@ method: "POST", | ||
expect(data.data).toBe("foobar"); | ||
}); | ||
it("should be possible to POST not yet ended stream-data", async () => { | ||
})); | ||
it.concurrent("should be possible to POST not yet ended stream-data", wrapContext(async (fetch) => { | ||
const stream = through2(); | ||
const eventualResponse = fetch(`${host}/post`, { | ||
allowForbiddenHeaders: true, | ||
body: new __1.StreamBody(stream), | ||
body: new index_1.StreamBody(stream), | ||
headers: { "content-length": "6" }, | ||
@@ -83,5 +87,5 @@ method: "POST", | ||
expect(data.data).toBe("foobar"); | ||
}); | ||
it("should save and forward cookies", async () => { | ||
const { fetch, disconnectAll } = __1.context(); | ||
})); | ||
it.concurrent("should save and forward cookies", async () => { | ||
const { fetch, disconnectAll } = index_1.context(); | ||
const responseSet = await fetch(`${host}/cookies/set?foo=bar`, { redirect: "manual" }); | ||
@@ -95,4 +99,4 @@ expect(responseSet.headers.has("location")).toBe(true); | ||
}); | ||
it("should handle (and follow) relative paths", async () => { | ||
const { fetch, disconnectAll } = __1.context(); | ||
it.concurrent("should handle (and follow) relative paths", async () => { | ||
const { fetch, disconnectAll } = index_1.context(); | ||
const response = await fetch(`${host}/relative-redirect/2`, { redirect: "follow" }); | ||
@@ -103,9 +107,9 @@ expect(response.url).toBe(`${host}/get`); | ||
}); | ||
it("should be possible to GET gzip data", async () => { | ||
it.concurrent("should be possible to GET gzip data", wrapContext(async (fetch) => { | ||
const response = await fetch(`${host}/gzip`); | ||
const data = await response.json(); | ||
expect(data).toMatchObject({ gzipped: true, method: "GET" }); | ||
}); | ||
})); | ||
}); | ||
}); | ||
//# sourceMappingURL=httpbin.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
const utils_2 = require("../../lib/utils"); | ||
const __1 = require("../../"); | ||
const index_1 = require("../../index"); | ||
async function getRejection(promise) { | ||
@@ -22,7 +22,2 @@ try { | ||
} | ||
function ensureStatusSuccess(response) { | ||
if (response.status < 200 || response.status >= 300) | ||
throw new Error("Status not 2xx"); | ||
return response; | ||
} | ||
[ | ||
@@ -37,11 +32,12 @@ { proto: "http:", version: "http1" }, | ||
const { disconnectAll, fetch, onPush } = (proto === "http:" && version === "http1") | ||
? { disconnectAll: __1.disconnectAll, fetch: __1.fetch, onPush: __1.onPush } | ||
: __1.context({ ...cycleOpts }); | ||
? { disconnectAll: index_1.disconnectAll, fetch: index_1.fetch, onPush: index_1.onPush } | ||
: index_1.context({ ...cycleOpts }); | ||
const protoVersion = `${version} over ${proto.replace(":", "")}`; | ||
describe("basic", () => { | ||
afterEach(disconnectAll); | ||
describe(`(${version} over ${proto.replace(":", "")})`, () => { | ||
describe(`generic (${protoVersion})`, () => { | ||
it("should be able to perform simple GET", async () => { | ||
const { server, port } = await makeServer(); | ||
const headers = version === "http1" ? { "http1-path": "/headers" } : {}; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { headers })); | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { headers })); | ||
const res = await response.json(); | ||
@@ -62,5 +58,5 @@ if (version === "http1") | ||
}; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { | ||
allowForbiddenHeaders: true, | ||
body: new __1.DataBody("foobar"), | ||
body: new index_1.DataBody("foobar"), | ||
headers, | ||
@@ -93,5 +89,5 @@ method: "POST", | ||
}; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { | ||
allowForbiddenHeaders: true, | ||
body: new __1.DataBody("foobar"), | ||
body: new index_1.DataBody("foobar"), | ||
headers, | ||
@@ -111,3 +107,3 @@ method: "POST", | ||
allowForbiddenHeaders: true, | ||
body: new __1.StreamBody(stream), | ||
body: new index_1.StreamBody(stream), | ||
headers: { "content-length": "6" }, | ||
@@ -119,3 +115,3 @@ method: "POST", | ||
stream.end(); | ||
const response = ensureStatusSuccess(await eventualResponse); | ||
const response = utils_1.ensureStatusSuccess(await eventualResponse); | ||
const data = await response.text(); | ||
@@ -130,3 +126,3 @@ expect(data).toBe("foobar"); | ||
const eventualResponse = fetch(`${proto}//localhost:${port}/echo`, { | ||
body: new __1.StreamBody(stream), | ||
body: new index_1.StreamBody(stream), | ||
method: "POST", | ||
@@ -137,3 +133,3 @@ }); | ||
stream.end(); | ||
const response = ensureStatusSuccess(await eventualResponse); | ||
const response = utils_1.ensureStatusSuccess(await eventualResponse); | ||
const data = await response.text(); | ||
@@ -262,3 +258,3 @@ expect(data).toBe("foobar"); | ||
allowForbiddenHeaders: true, | ||
body: new __1.StreamBody(stream), | ||
body: new index_1.StreamBody(stream), | ||
headers: { "content-length": "" + chunkSize * chunks }, | ||
@@ -268,3 +264,3 @@ method: "POST", | ||
await already_1.delay(1); | ||
const response = ensureStatusSuccess(await eventualResponse); | ||
const response = utils_1.ensureStatusSuccess(await eventualResponse); | ||
const data = await response.text(); | ||
@@ -293,7 +289,7 @@ expect(data).toBe(referenceHash); | ||
const eventualResponse = fetch(`${proto}//localhost:${port}/sha256`, { | ||
body: new __1.StreamBody(stream), | ||
body: new index_1.StreamBody(stream), | ||
method: "POST", | ||
}); | ||
await already_1.delay(1); | ||
const response = ensureStatusSuccess(await eventualResponse); | ||
const response = utils_1.ensureStatusSuccess(await eventualResponse); | ||
const data = await response.text(); | ||
@@ -312,3 +308,3 @@ expect(data).toBe(referenceHash); | ||
const data = { foo: "bar" }; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/push`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/push`, { | ||
json: [ | ||
@@ -333,3 +329,3 @@ { | ||
const host = "localhost"; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`, { | ||
allowForbiddenHeaders: true, | ||
@@ -347,3 +343,3 @@ headers: { host }, | ||
const { server, port } = await makeServer(); | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`)); | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/headers`)); | ||
const responseData = await response.json(); | ||
@@ -356,3 +352,3 @@ expect(responseData["accept-encoding"]).toContain("gzip"); | ||
const testData = { foo: "bar" }; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/compressed/gzip`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/compressed/gzip`, { | ||
json: testData, | ||
@@ -370,3 +366,3 @@ method: "POST", | ||
const testData = { foo: "bar" }; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/compressed/deflate`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/compressed/deflate`, { | ||
json: testData, | ||
@@ -386,3 +382,3 @@ method: "POST", | ||
const testData = { foo: "bar" }; | ||
const response = ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/compressed/br`, { | ||
const response = utils_1.ensureStatusSuccess(await fetch(`${proto}//localhost:${port}/compressed/br`, { | ||
json: testData, | ||
@@ -398,7 +394,7 @@ method: "POST", | ||
}); | ||
describe(`response (${proto})`, () => { | ||
describe(`response (${protoVersion})`, () => { | ||
it("should have a proper url", async () => { | ||
const { server, port } = await makeServer(); | ||
const url = `${proto}//localhost:${port}/headers`; | ||
const response = ensureStatusSuccess(await fetch(url)); | ||
const response = utils_1.ensureStatusSuccess(await fetch(url)); | ||
expect(response.url).toBe(utils_1.cleanUrl(url)); | ||
@@ -410,3 +406,3 @@ await disconnectAll(); | ||
if (version === "http2") | ||
describe(`goaway (${proto})`, () => { | ||
describe(`goaway (${protoVersion})`, () => { | ||
if (proto === "http:") // This race is too fast for TLS | ||
@@ -417,5 +413,5 @@ it("handle session failover (race conditioned)", async () => { | ||
const url2 = `${proto}//localhost:${port}/headers`; | ||
const response1 = ensureStatusSuccess(await fetch(url1)); | ||
const response1 = utils_1.ensureStatusSuccess(await fetch(url1)); | ||
expect(response1.url).toBe(utils_1.cleanUrl(url1)); | ||
const response2 = ensureStatusSuccess(await fetch(url2)); | ||
const response2 = utils_1.ensureStatusSuccess(await fetch(url2)); | ||
expect(response2.url).toBe(utils_1.cleanUrl(url2)); | ||
@@ -431,6 +427,6 @@ await response1.text(); | ||
const url2 = `${proto}//localhost:${port}/headers`; | ||
const response1 = ensureStatusSuccess(await fetch(url1)); | ||
const response1 = utils_1.ensureStatusSuccess(await fetch(url1)); | ||
expect(response1.url).toBe(utils_1.cleanUrl(url1)); | ||
await already_1.delay(20); | ||
const response2 = ensureStatusSuccess(await fetch(url2)); | ||
const response2 = utils_1.ensureStatusSuccess(await fetch(url2)); | ||
expect(response2.url).toBe(utils_1.cleanUrl(url2)); | ||
@@ -446,6 +442,6 @@ await response1.text(); | ||
const url2 = `${proto}//localhost:${port}/slow/50`; | ||
const response1 = ensureStatusSuccess(await fetch(url1)); | ||
const response1 = utils_1.ensureStatusSuccess(await fetch(url1)); | ||
expect(response1.url).toBe(utils_1.cleanUrl(url1)); | ||
await already_1.delay(10); | ||
const response2 = ensureStatusSuccess(await fetch(url2)); | ||
const response2 = utils_1.ensureStatusSuccess(await fetch(url2)); | ||
expect(response2.url).toBe(utils_1.cleanUrl(url2)); | ||
@@ -461,3 +457,3 @@ await already_1.delay(10); | ||
}); | ||
describe(`integrity (${proto})`, () => { | ||
describe(`integrity (${protoVersion})`, () => { | ||
it("handle and succeed on valid integrity", async () => { | ||
@@ -468,3 +464,3 @@ const { server, port } = await makeServer(); | ||
const integrity = utils_1.createIntegrity(data); | ||
const response = ensureStatusSuccess(await fetch(url, { integrity })); | ||
const response = utils_1.ensureStatusSuccess(await fetch(url, { integrity })); | ||
expect(response.url).toBe(utils_1.cleanUrl(url)); | ||
@@ -480,3 +476,3 @@ expect(await response.text()).toBe(data); | ||
const integrity = utils_1.createIntegrity(data); | ||
const response = ensureStatusSuccess(await fetch(url, { integrity })); | ||
const response = utils_1.ensureStatusSuccess(await fetch(url, { integrity })); | ||
expect(response.url).toBe(utils_1.cleanUrl(url)); | ||
@@ -494,3 +490,3 @@ try { | ||
}); | ||
describe(`premature stream close (${proto})`, () => { | ||
describe(`premature stream close (${protoVersion})`, () => { | ||
it("handle and reject fetch operation", async () => { | ||
@@ -497,0 +493,0 @@ const { server, port } = await makeServer(); |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import { Server as HttpsServer } from "https"; | ||
import { HttpProtocols } from "../../"; | ||
import { HttpProtocols } from "../../index"; | ||
export interface TestData { | ||
@@ -8,0 +8,0 @@ proto: "http:" | "https:"; |
@@ -155,2 +155,15 @@ "use strict"; | ||
} | ||
else if (path.startsWith("/delay/")) { | ||
const waitMs = parseInt(path.replace("/delay/", ""), 10); | ||
if (waitMs > 0) | ||
await already_1.delay(waitMs); | ||
const responseHeaders = { | ||
":status": 200, | ||
[HTTP2_HEADER_CONTENT_LENGTH]: "10", | ||
}; | ||
sendHeaders(responseHeaders); | ||
response.write("abcde"); | ||
server_common_1.ignoreError(() => response.write("fghij")); | ||
server_common_1.ignoreError(() => response.end()); | ||
} | ||
else if (path.startsWith("/slow/")) { | ||
@@ -157,0 +170,0 @@ const waitMs = parseInt(path.replace("/slow/", ""), 10); |
@@ -6,2 +6,3 @@ /// <reference types="node" /> | ||
private _sessions; | ||
private _awaits; | ||
constructor(opts: ServerOptions); | ||
@@ -8,0 +9,0 @@ _shutdown(): Promise<void>; |
@@ -13,2 +13,3 @@ "use strict"; | ||
super(); | ||
this._awaits = []; | ||
this._opts = opts || {}; | ||
@@ -22,7 +23,13 @@ if (this._opts.serverOptions) | ||
this._server.on("stream", (stream, headers) => { | ||
this.onStream(stream, headers) | ||
const awaitStream = this.onStream(stream, headers) | ||
.catch(err => { | ||
console.error("Unit test server failed", err); | ||
console.error("Unit test server failed", err.stack); | ||
process.exit(1); | ||
}) | ||
.then(() => { | ||
const index = this._awaits.findIndex(promise => promise === awaitStream); | ||
if (index !== -1) | ||
this._awaits.splice(index, 1); | ||
}); | ||
this._awaits.push(awaitStream); | ||
}); | ||
@@ -34,2 +41,3 @@ } | ||
} | ||
await Promise.all(this._awaits); | ||
this._sessions.clear(); | ||
@@ -187,2 +195,15 @@ } | ||
} | ||
else if (path.startsWith("/delay/")) { | ||
const waitMs = parseInt(path.replace("/delay/", ""), 10); | ||
if (waitMs > 0) | ||
await already_1.delay(waitMs); | ||
const responseHeaders = { | ||
":status": 200, | ||
[HTTP2_HEADER_CONTENT_LENGTH]: "10", | ||
}; | ||
server_common_1.ignoreError(() => stream.respond(responseHeaders)); | ||
server_common_1.ignoreError(() => stream.write("abcde")); | ||
server_common_1.ignoreError(() => stream.write("fghij")); | ||
server_common_1.ignoreError(() => stream.end()); | ||
} | ||
else if (path.startsWith("/slow/")) { | ||
@@ -212,2 +233,4 @@ const waitMs = parseInt(path.replace("/slow/", ""), 10); | ||
} | ||
if (!stream.closed) | ||
return new Promise(resolve => stream.once("close", resolve)); | ||
} | ||
@@ -214,0 +237,0 @@ } |
@@ -0,2 +1,4 @@ | ||
import { Response } from "../../index"; | ||
export declare function createIntegrity(data: string, hashType?: string): string; | ||
export declare const cleanUrl: (url: string) => string; | ||
export declare function ensureStatusSuccess(response: Response): Response; |
@@ -11,2 +11,8 @@ "use strict"; | ||
exports.cleanUrl = (url) => url.replace(/^http[12]:\/\//, "http://"); | ||
function ensureStatusSuccess(response) { | ||
if (response.status < 200 || response.status >= 300) | ||
throw new Error("Status not 2xx"); | ||
return response; | ||
} | ||
exports.ensureStatusSuccess = ensureStatusSuccess; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "fetch-h2", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "HTTP/1+2 Fetch API client for Node.js", | ||
@@ -25,7 +25,8 @@ "author": "Gustaf Räntilä", | ||
"jest:debug": "node --inspect-brk node_modules/.bin/jest", | ||
"test": "npm run lint && npm run jest --coverage", | ||
"test": "npm run lint && node_modules/.bin/jest --forceExit --detectOpenHandles --coverage", | ||
"buildtest": "npm run build && npm run jest", | ||
"buildtestcov": "npm run build && npm run test", | ||
"coverage": "node_modules/.bin/nyc report --reporter=html", | ||
"version": "./node_modules/.bin/ts-node scripts/version-update.ts && npm run buildtest && scripts/version-git-add.sh", | ||
"coveralls": "cat coverage/lcov.info | node_modules/.bin/coveralls", | ||
"version": "./node_modules/.bin/ts-node scripts/version-update.ts && npm run build && npm run test && scripts/version-git-add.sh", | ||
"prepack": "npm run build && npm run test", | ||
@@ -32,0 +33,0 @@ "makecerts": "openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout certs/key.pem -out certs/cert.pem", |
@@ -57,2 +57,3 @@ [![npm version][npm-image]][npm-url] | ||
AbortError, | ||
AbortController, | ||
TimeoutError, | ||
@@ -71,4 +72,8 @@ | ||
Apart from the obvious `fetch`, the functions `setup`, `context`, `disconnect`, `disconnectAll` and `onPush` are described below, and the classes [`Body`](https://developer.mozilla.org/docs/Web/API/Body), [`Headers`](https://developer.mozilla.org/docs/Web/API/Headers), [`Request`](https://developer.mozilla.org/docs/Web/API/Request) and [`Response`](https://developer.mozilla.org/docs/Web/API/Response) are part of the [Fetch API](https://developer.mozilla.org/docs/Web/API/Fetch_API). `AbortError` is the error thrown in case of an [abort signal](https://developer.mozilla.org/docs/Web/API/AbortSignal) (this is also the error thrown in case of a *timeout*, which in `fetch-h2` is internally implemented as an abort signal), `TimeoutError` is thrown if the request times out. | ||
Apart from the obvious `fetch`, the functions `setup`, `context`, `disconnect`, `disconnectAll` and `onPush` are described below, and the classes [`Body`](https://developer.mozilla.org/docs/Web/API/Body), [`Headers`](https://developer.mozilla.org/docs/Web/API/Headers), [`Request`](https://developer.mozilla.org/docs/Web/API/Request) and [`Response`](https://developer.mozilla.org/docs/Web/API/Response) are part of the [Fetch API](https://developer.mozilla.org/docs/Web/API/Fetch_API). | ||
`AbortError` is the error thrown in case of an [abort signal](https://developer.mozilla.org/docs/Web/API/AbortSignal) (this is also the error thrown in case of a *timeout*, which in `fetch-h2` is internally implemented as an abort signal) and the [`AbortController`](https://developer.mozilla.org/docs/Web/API/AbortController) provides a way to abort requests. | ||
`TimeoutError` is thrown if the request times out. | ||
The `ContextOptions`, `DecodeFunction` and `Decoder` types are described below. | ||
@@ -313,3 +318,3 @@ | ||
`http1.keepAlive` defaults to false, but can be set to true, to allow connections to linger so that they can be reused. The `http1.keepAliveMsecs` time (defaults to 1000ms, i.e. 1s) specifies the delay before keep-alive probing. | ||
`http1.keepAlive` defaults to true, to allow connections to linger so that they can be reused. The `http1.keepAliveMsecs` time (defaults to 1000ms, i.e. 1s) specifies the delay before keep-alive probing. | ||
@@ -316,0 +321,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
352846
99
4524
395
72