http2-wrapper
Advanced tools
Comparing version 1.0.0-beta.4.4 to 1.0.0-beta.4.5
{ | ||
"name": "http2-wrapper", | ||
"version": "1.0.0-beta.4.4", | ||
"version": "1.0.0-beta.4.5", | ||
"description": "HTTP2 client, just with the familiar `https` API", | ||
@@ -41,3 +41,3 @@ "main": "source", | ||
"get-stream": "^5.1.0", | ||
"got": "^10.5.5", | ||
"got": "^11.0.2", | ||
"lolex": "^6.0.0", | ||
@@ -44,0 +44,0 @@ "many-keys-map": "^1.0.2", |
@@ -8,2 +8,3 @@ 'use strict'; | ||
const proxyEvents = require('./utils/proxy-events'); | ||
const isRequestPseudoHeader = require('./utils/is-request-pseudo-header'); | ||
const { | ||
@@ -19,3 +20,2 @@ ERR_INVALID_ARG_TYPE, | ||
const { | ||
NGHTTP2_CANCEL, | ||
HTTP2_HEADER_STATUS, | ||
@@ -32,2 +32,3 @@ HTTP2_HEADER_METHOD, | ||
const kFlushedHeaders = Symbol('flushedHeaders'); | ||
const kJobs = Symbol('jobs'); | ||
@@ -39,3 +40,5 @@ const isValidHttpToken = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/; | ||
constructor(input, options, callback) { | ||
super(); | ||
super({ | ||
autoDestroy: false | ||
}); | ||
@@ -88,2 +91,3 @@ const hasInput = typeof input === 'string' || input instanceof URL; | ||
this[kHeaders] = Object.create(null); | ||
this[kJobs] = []; | ||
@@ -102,3 +106,3 @@ this.socket = null; | ||
for (const [header, value] of Object.entries(options.headers)) { | ||
this[kHeaders][header.toLowerCase()] = value; | ||
this.setHeader(header, value); | ||
} | ||
@@ -117,2 +121,3 @@ } | ||
// Clients that generate HTTP/2 requests directly SHOULD use the :authority pseudo-header field instead of the Host header field. | ||
// What about IPv6? Square brackets? | ||
if (options.port === 443) { | ||
@@ -172,3 +177,3 @@ options.origin = `https://${options.host}`; | ||
} else { | ||
this.once('socket', callWrite); | ||
this[kJobs].push(callWrite); | ||
} | ||
@@ -178,3 +183,3 @@ } | ||
_final(callback) { | ||
if (this.destroyed || this.aborted) { | ||
if (this.destroyed) { | ||
return; | ||
@@ -189,3 +194,3 @@ } | ||
} else { | ||
this.once('socket', callEnd); | ||
this[kJobs].push(callEnd); | ||
} | ||
@@ -195,2 +200,6 @@ } | ||
abort() { | ||
if (this.res && this.res.complete) { | ||
return; | ||
} | ||
if (!this.aborted) { | ||
@@ -202,2 +211,6 @@ process.nextTick(() => this.emit('abort')); | ||
this.destroy(); | ||
} | ||
_destroy(error, callback) { | ||
if (this.res) { | ||
@@ -208,16 +221,10 @@ this.res._dump(); | ||
if (this._request) { | ||
this._request.close(NGHTTP2_CANCEL); | ||
this._request.destroy(); | ||
} | ||
} | ||
_destroy(error) { | ||
if (this._request) { | ||
this._request.destroy(error); | ||
} else if (error) { | ||
process.nextTick(() => this.emit('error', error)); | ||
} | ||
callback(error); | ||
} | ||
async flushHeaders() { | ||
if (this[kFlushedHeaders] || this.destroyed || this.aborted) { | ||
if (this[kFlushedHeaders] || this.destroyed) { | ||
return; | ||
@@ -234,4 +241,4 @@ } | ||
if (this.destroyed || this.aborted) { | ||
stream.close(NGHTTP2_CANCEL); | ||
if (this.destroyed) { | ||
stream.destroy(); | ||
return; | ||
@@ -263,2 +270,6 @@ } | ||
response.complete = true; | ||
// Has no effect, just be consistent with the Node.js behavior | ||
response.socket = null; | ||
response.connection = null; | ||
} | ||
@@ -301,13 +312,18 @@ }); | ||
stream.once('trailers', (trailers, flags, rawTrailers) => { | ||
const {res} = this; | ||
// Assigns trailers to the response object. | ||
this.res.trailers = trailers; | ||
this.res.rawTrailers = rawTrailers; | ||
res.trailers = trailers; | ||
res.rawTrailers = rawTrailers; | ||
}); | ||
this.socket = stream.session.socket; | ||
this.connection = stream.session.socket; | ||
const {socket} = stream.session; | ||
this.socket = socket; | ||
this.connection = socket; | ||
process.nextTick(() => { | ||
this.emit('socket', this.socket); | ||
}); | ||
for (const job of this[kJobs]) { | ||
job(); | ||
} | ||
this.emit('socket', this.socket); | ||
}; | ||
@@ -364,3 +380,3 @@ | ||
if (typeof name !== 'string' || !isValidHttpToken.test(name)) { | ||
if (typeof name !== 'string' || (!isValidHttpToken.test(name) && !isRequestPseudoHeader(name))) { | ||
throw new ERR_INVALID_HTTP_TOKEN('Header name', name); | ||
@@ -389,8 +405,8 @@ } | ||
setTimeout(ms, callback) { | ||
const applyTimeout = () => this._request.setTimeout(ms, callback); | ||
if (this._request) { | ||
this._request.setTimeout(ms, callback); | ||
applyTimeout(); | ||
} else { | ||
this.once('socket', () => { | ||
this._request.setTimeout(ms, callback); | ||
}); | ||
this[kJobs].push(applyTimeout); | ||
} | ||
@@ -402,3 +418,3 @@ | ||
get maxHeadersCount() { | ||
if (this._request) { | ||
if (!this.destroyed && this._request) { | ||
return this._request.session.localSettings.maxHeaderListSize; | ||
@@ -405,0 +421,0 @@ } |
@@ -6,3 +6,6 @@ 'use strict'; | ||
constructor(socket, highWaterMark) { | ||
super({highWaterMark}); | ||
super({ | ||
highWaterMark, | ||
autoDestroy: false | ||
}); | ||
@@ -9,0 +12,0 @@ this.statusCode = null; |
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
48095
13
1105