diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19878c510..f7cbb1b7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,14 +55,8 @@ jobs: strategy: fail-fast: false matrix: - node-version: [6, 8] - include: - - node-version: 10 - # todo: enable coverage after figuring out why test-cov step is failing - coverage: false - - node-version: 16 - legacy-peer-deps: true - + node-version: [16] + steps: - name: Checkout repository uses: actions/checkout@v3 @@ -72,21 +66,12 @@ jobs: with: node-version: ${{ matrix.node-version }} - - if: ${{ matrix.legacy-peer-deps }} - name: Install with legacy peer deps + - name: Install with legacy peer deps run: npm install --legacy-peer-deps - - - if: ${{ !matrix.legacy-peer-deps }} - name: Install - run: npm install - name: Compile TS run: tsc lib/**/*.ts - - if: ${{ ! matrix.coverage }} - name: Run tests - run: npm run test-ci - - if: ${{ matrix.coverage }} name: Run tests and upload coverage run: npm run test-cov && npx codecov && cat ./coverage/lcov.info | npx coveralls diff --git a/index.js b/index.js index f6a32ba52..25181edfa 100755 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ function initParams (uri, options, callback) { callback = options } - var params = {httpVersion: 'http1'} + var params = {protocolVersion: 'http1'} 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 624825d5f..30dac48d9 100644 --- a/lib/autohttp/agent.ts +++ b/lib/autohttp/agent.ts @@ -4,7 +4,7 @@ import * as https from "https"; import {RequestOptions} from "../http2/request"; import {MultiProtocolRequest} from "./request"; import * as tls from "tls"; -import {EventEmitter} from "node:events"; +import {EventEmitter} from "events"; interface AgentOptions extends Http2AgentOptions { diff --git a/lib/autohttp/request.ts b/lib/autohttp/request.ts index bfd3250df..b04c8c291 100644 --- a/lib/autohttp/request.ts +++ b/lib/autohttp/request.ts @@ -1,9 +1,9 @@ import * as http from "http"; import * as http2 from "http2"; -import {EventEmitter} from "node:events"; +import {EventEmitter} from "events"; import { RequestOptions, Request as HTTP2Request} from '../../lib/http2/request' import {AutoHttp2Agent} from "./agent"; -import {ClientRequest} from "node:http"; +import {ClientRequest} from "http"; diff --git a/lib/http2/http2Agent.ts b/lib/http2/http2Agent.ts index d0c86ee34..e397e09f4 100644 --- a/lib/http2/http2Agent.ts +++ b/lib/http2/http2Agent.ts @@ -1,4 +1,4 @@ -import {EventEmitter} from "node:events"; +import {EventEmitter} from "events"; import * as http2 from "http2"; import * as tls from "tls"; import {RequestOptions} from "./request"; diff --git a/lib/http2/request.ts b/lib/http2/request.ts index e0341d9b1..0adc78c5b 100644 --- a/lib/http2/request.ts +++ b/lib/http2/request.ts @@ -1,7 +1,7 @@ -import {URL} from "node:url"; +import {URL} from "url"; import * as http from "http"; import * as http2 from 'http2'; -import {EventEmitter} from "node:events"; +import {EventEmitter} from "events"; import {Http2Agent} from "./http2Agent"; export interface RequestOptions { diff --git a/package.json b/package.json index 1d61d562f..0d954e64f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "license": "Apache-2.0", "engines": { - "node": ">= 6" + "node": ">= 16" }, "main": "index.js", "files": [ @@ -76,8 +76,7 @@ "server-destroy": "^1.0.1", "standard": "^9.0.0", "tape": "^4.6.0", - "taper": "^0.5.0", - "typescript": "^5.4.5" + "taper": "^0.5.0" }, "greenkeeper": { "ignore": [ diff --git a/request.js b/request.js index 443b3c464..88acec5eb 100644 --- a/request.js +++ b/request.js @@ -595,7 +595,7 @@ Request.prototype.init = function (options) { // 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] + self.httpModule = httpModules[protocol]?.[options.protocolVersion] || httpModules[protocol] || defaultModules[protocol][options.protocolVersion] if (!self.httpModule) { return self.emit('error', new Error('Invalid protocol: ' + protocol)) @@ -891,7 +891,7 @@ Request.prototype.getNewAgent = function () { } // we're using a stored agent. Make sure it's protocol-specific - poolKey = self.httpVersion + ':' + self.uri.protocol + poolKey + poolKey = self.protocolVersion + ':' + self.uri.protocol + poolKey // generate a new agent for this setting if none yet exists if (!self.pool[poolKey]) { diff --git a/test.js b/test.js index 5c6f8cdc4..225686416 100644 --- a/test.js +++ b/test.js @@ -7,9 +7,9 @@ const TEST_URL = "https://postman-echo.com/get"; const httpsurl = 'https://localhost:443' const http2url = 'https://localhost:3000/h2' const pool = {}; -const proto = 'auto'; +const proto = 'h2'; const r = request(TEST_URL,{ - httpVersion: proto, + protocolVersion: proto, timing:true, strictSSL:true, gzip:true, @@ -24,7 +24,7 @@ const r = request(TEST_URL,{ }, (err, resp, body)=> { console.log(resp?.timings, err, body); request(TEST_URL,{ - httpVersion: proto, + protocolVersion: proto, timing:true, strictSSL:true, gzip:true, @@ -38,6 +38,7 @@ const r = request(TEST_URL,{ // cert: fs.readFileSync('/Users/parth.verma@postman.com/temp/t/cert.pem') }, (err, resp, body)=> { console.log(resp?.timings) + console.log(resp.httpVersion ) // console.log({body}); // }) diff --git a/tests/test-node-debug.js b/tests/test-node-debug.js index bcc6a401d..fcc63ba84 100644 --- a/tests/test-node-debug.js +++ b/tests/test-node-debug.js @@ -37,7 +37,7 @@ tape('a simple request should not fail with debugging enabled', function (t) { t.ok(stderr.length, 'stderr has some messages') var url = s.url.replace(/\//g, '\\/') var patterns = [ - /^REQUEST { uri: /, + /^REQUEST {\n protocolVersion: /, new RegExp('^REQUEST make request ' + url + '/\n$'), /^REQUEST onRequestResponse /, /^REQUEST finish init /,