Comparing version 2.0.0 to 2.0.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tls_1 = require("tls"); | ||
const core_1 = require("./core"); | ||
const alpnProtocols = { | ||
@@ -9,2 +8,3 @@ http1: Buffer.from("\x08http/1.1"), | ||
}; | ||
const defaultMethod = ["http2", "http1"]; | ||
function connectTLS(host, port, protocols, connOpts) { | ||
@@ -20,3 +20,4 @@ const usedProtocol = new Set(); | ||
}); | ||
const orderedProtocols = Buffer.concat(_protocols.map(protocol => alpnProtocols[protocol])); | ||
const orderedProtocols = Buffer.concat((_protocols.length === 0 ? _protocols : defaultMethod) | ||
.map(protocol => alpnProtocols[protocol])); | ||
const opts = { | ||
@@ -32,4 +33,10 @@ ...connOpts, | ||
return reject(authorizationError); | ||
if (!["h2", "http/1.1", "http/1.0"].includes(alpnProtocol)) | ||
return reject(new core_1.FetchError("Invalid ALPN response")); | ||
if (!["h2", "http/1.1", "http/1.0"].includes(alpnProtocol)) { | ||
// Maybe the server doesn't understand ALPN, enforce | ||
// user-provided protocol, or fallback to HTTP/1 | ||
if (_protocols.length === 1) | ||
return resolve({ protocol: _protocols[0], socket }); | ||
else | ||
return resolve({ protocol: "http1", socket }); | ||
} | ||
const protocol = alpnProtocol === "h2" ? "http2" : "http1"; | ||
@@ -36,0 +43,0 @@ resolve({ socket, protocol }); |
@@ -1,1 +0,1 @@ | ||
export declare const version = "2.0.0"; | ||
export declare const version = "2.0.1"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = "2.0.0"; | ||
exports.version = "2.0.1"; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "fetch-h2", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "HTTP/2-only Fetch API client for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "Gustaf Räntilä", |
Sorry, the diff of this file is not supported yet
320459
4111