From e3d302faec78b52a3c6dd3290a95442e40afdf9c Mon Sep 17 00:00:00 2001 From: Parth Verma Date: Wed, 5 Jun 2024 15:59:14 -0700 Subject: [PATCH] added abort method to http2 request --- index.js | 3 ++- lib/autohttp/agent.ts | 5 +++-- lib/http2/request.ts | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 25181edfa..d8aa0305d 100755 --- a/index.js +++ b/index.js @@ -24,7 +24,8 @@ function initParams (uri, options, callback) { callback = options } - var params = {protocolVersion: 'http1'} + var params = {protocolVersion: 'auto'} + console.log('params', params) if (options !== null && typeof options === 'object') { extend(params, options, {uri: uri}) } else if (typeof uri === 'string') { diff --git a/lib/autohttp/agent.ts b/lib/autohttp/agent.ts index 52b19e8b5..bf664f4a9 100644 --- a/lib/autohttp/agent.ts +++ b/lib/autohttp/agent.ts @@ -19,7 +19,8 @@ export class AutoHttp2Agent extends EventEmitter implements Agent { constructor(options: AgentOptions) { super(); this.http2Agent = new Http2Agent(options); - this.httpsAgent = new https.Agent({...options, keepAlive: true, timeout: 3000}); + // @ts-ignore + this.httpsAgent = new https.Agent({...options, ...options.agentOptions}); this.ALPNCache = new Map(); } @@ -38,7 +39,7 @@ export class AutoHttp2Agent extends EventEmitter implements Agent { process.nextTick(()=>this.emit('h2', connection)); return; } - if(protocol === 'http/1.1'){ + if(protocol === 'http/1.1' || protocol === 'http/1.0'){ // console.log('using cached alpn'); const requestOptions: https.RequestOptions = { port: options.port ?? 443, diff --git a/lib/http2/request.ts b/lib/http2/request.ts index ba43cd8cb..38ab13016 100644 --- a/lib/http2/request.ts +++ b/lib/http2/request.ts @@ -167,6 +167,11 @@ export class Request extends EventEmitter { this._req.setTimeout(timeout, cb); } + + abort(){ + this._req.destroy(); + } + } export function request(options): http.ClientRequest { // @ts-ignore