@httptoolkit/httpolyglot
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -13,2 +13,3 @@ "use strict"; | ||
const HTTP2_PREFACE_BUFFER = Buffer.from(HTTP2_PREFACE); | ||
const NODE_MAJOR_VERSION = parseInt(process.version.slice(1).split('.')[0], 10); | ||
class Server extends net.Server { | ||
@@ -112,8 +113,15 @@ constructor(configOrListener, listener) { | ||
// We have a full match for the preface - it's definitely HTTP/2. | ||
// For HTTP/2 we hit issues when passing non-socket streams (like HTTP/2 streams, | ||
// for proxying H2-over-H2). Marking the sockets like this resolves that: | ||
const socketWithInternals = socket; | ||
if (socketWithInternals._handle) { | ||
socketWithInternals._handle.isStreamBase = false; | ||
// For HTTP/2 we hit issues when passing non-socket streams (like H2 streams for proxying H2-over-H2). | ||
if (NODE_MAJOR_VERSION <= 12) { | ||
// For Node 12 and older, we need a (later deprecated) stream wrapper: | ||
const StreamWrapper = require('_stream_wrap'); | ||
socket = new StreamWrapper(socket); | ||
} | ||
else { | ||
// For newer node, we can fix this with a quick patch here: | ||
const socketWithInternals = socket; | ||
if (socketWithInternals._handle) { | ||
socketWithInternals._handle.isStreamBase = false; | ||
} | ||
} | ||
h2Server.emit('connection', socket); | ||
@@ -120,0 +128,0 @@ return; |
{ | ||
"name": "@httptoolkit/httpolyglot", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"author": "Tim Perry <pimterry@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Serve http and https connections over the same port with node.js", |
@@ -21,2 +21,4 @@ import * as net from 'net'; | ||
const NODE_MAJOR_VERSION = parseInt(process.version.slice(1).split('.')[0], 10); | ||
type Http2Listener = (request: http2.Http2ServerRequest, response: http2.Http2ServerResponse) => void; | ||
@@ -140,7 +142,13 @@ | ||
// For HTTP/2 we hit issues when passing non-socket streams (like HTTP/2 streams, | ||
// for proxying H2-over-H2). Marking the sockets like this resolves that: | ||
const socketWithInternals = socket as { _handle?: { isStreamBase?: boolean } }; | ||
if (socketWithInternals._handle) { | ||
socketWithInternals._handle.isStreamBase = false; | ||
// For HTTP/2 we hit issues when passing non-socket streams (like H2 streams for proxying H2-over-H2). | ||
if (NODE_MAJOR_VERSION <= 12) { | ||
// For Node 12 and older, we need a (later deprecated) stream wrapper: | ||
const StreamWrapper = require('_stream_wrap'); | ||
socket = new StreamWrapper(socket); | ||
} else { | ||
// For newer node, we can fix this with a quick patch here: | ||
const socketWithInternals = socket as { _handle?: { isStreamBase?: boolean } }; | ||
if (socketWithInternals._handle) { | ||
socketWithInternals._handle.isStreamBase = false; | ||
} | ||
} | ||
@@ -147,0 +155,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24213
323