Skip to content

Commit

Permalink
Fixed regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 committed Jun 3, 2024
1 parent b1b7846 commit bf1e08d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function initParams (uri, options, callback) {
callback = options
}

var params = {protocol: 'http1'}
var params = {httpVersion: 'http1'}
if (options !== null && typeof options === 'object') {
extend(params, options, {uri: uri})
} else if (typeof uri === 'string') {
Expand Down
6 changes: 3 additions & 3 deletions lib/autohttp/agent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Agent} from 'https';
import {Http2Agent} from "../http2/http2Agent";
import {Http2Agent, type AgentOptions as Http2AgentOptions} from "../http2/http2Agent";
import * as https from "https";
import {RequestOptions} from "../http2/request";
import {MultiProtocolRequest} from "./request";
import * as tls from "tls";
import {EventEmitter} from "node:events";


interface AgentOptions extends Omit<RequestOptions, 'agent'> {
interface AgentOptions extends Http2AgentOptions {
}

// @ts-ignore
Expand All @@ -23,7 +23,7 @@ export class AutoHttp2Agent extends EventEmitter implements Agent {
this.ALPNCache = new Map();
}

createConnection(req: MultiProtocolRequest, options: AgentOptions) {
createConnection(req: MultiProtocolRequest, options: RequestOptions) {
const uri = options.uri;
const port = options.port ?? 443;

Expand Down
3 changes: 2 additions & 1 deletion lib/autohttp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import {request} from "./request";

export default {
Agent: AutoHttp2Agent,
request: request
request: request,
globalAgent: new AutoHttp2Agent({})
}
2 changes: 1 addition & 1 deletion lib/http2/http2Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Options {

}

interface AgentOptions{
export interface AgentOptions{
ca?: Buffer;
extraCa?:string;
ciphers?: string;
Expand Down
4 changes: 3 additions & 1 deletion lib/http2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import {request} from "./request";

export default {
Agent: Http2Agent,
request: request
request: request,
globalAgent: new Http2Agent({})

}
2 changes: 2 additions & 0 deletions lib/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ Redirect.prototype.onResponse = function (response) {

request.emit('redirect')

options.httpVersion = this.request.httpVersion;

request.init(options)

return true
Expand Down
8 changes: 4 additions & 4 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ Request.prototype.init = function (options) {
var defaultModules = {'http:': { h2: http, http1: http, auto: http }, 'https:': { http1: https, h2: http2, auto: autohttp2 }}
var httpModules = self.httpModules || {}

self.httpModule = httpModules[protocol]?.[options.protocol] || defaultModules[protocol][options.protocol]
// If user defines httpModules, respect if they have different httpModules for different http versions, else use the tls specific http module
// If the user defines nothing, revert to default modules
self.httpModule = httpModules[protocol]?.[options.httpVersion] || httpModules[protocol] || defaultModules[protocol][options.httpVersion]

if (!self.httpModule) {
return self.emit('error', new Error('Invalid protocol: ' + protocol))
Expand Down Expand Up @@ -810,8 +812,6 @@ Request.prototype.getNewAgent = function () {
poolKey += Agent.name
}

poolKey += self.protocol;

// ca option is only relevant if proxy or destination are https
var proxy = self.proxy
if (typeof proxy === 'string') {
Expand Down Expand Up @@ -891,7 +891,7 @@ Request.prototype.getNewAgent = function () {
}

// we're using a stored agent. Make sure it's protocol-specific
poolKey = self.uri.protocol + poolKey
poolKey = self.httpVersion + ':' + self.uri.protocol + poolKey

// generate a new agent for this setting if none yet exists
if (!self.pool[poolKey]) {
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const http2url = 'https://localhost:3000/h2'
const pool = {};
const proto = 'auto';
const r = request(TEST_URL,{
protocol: proto,
httpVersion: proto,
timing:true,
strictSSL:true,
gzip:true,
Expand All @@ -24,7 +24,7 @@ const r = request(TEST_URL,{
}, (err, resp, body)=> {
console.log(resp?.timings, err, body);
request(TEST_URL,{
protocol: proto,
httpVersion: proto,
timing:true,
strictSSL:true,
gzip:true,
Expand Down

0 comments on commit bf1e08d

Please sign in to comment.