Skip to content

Commit

Permalink
added abort method to http2 request
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 committed Jun 5, 2024
1 parent e86d071 commit e3d302f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
5 changes: 3 additions & 2 deletions lib/autohttp/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions lib/http2/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3d302f

Please sign in to comment.