Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use node: prefix to bypass require.cache call for builtins #324

Merged
merged 2 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ socket server by using `querystring.escape(socketPath)` as the hostname. This i
for http2 nor undici. To illustrate:

```js
const socketPath = require('querystring').escape('/run/http-daemon.socket')
const socketPath = require('node:querystring').escape('/run/http-daemon.socket')
proxy.register(require('@fastify/reply-from'), {
base: 'unix+http://${socketPath}/'
});
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fp = require('fastify-plugin')
const { lru } = require('tiny-lru')
const querystring = require('fast-querystring')
const Stream = require('stream')
const Stream = require('node:stream')
const buildRequest = require('./lib/request')
const {
filterPseudoHeaders,
Expand Down
8 changes: 4 additions & 4 deletions lib/request.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'
const http = require('http')
const https = require('https')
const querystring = require('querystring')
const http = require('node:http')
const https = require('node:https')
const querystring = require('node:querystring')
const eos = require('end-of-stream')
const pump = require('pump')
const undici = require('undici')
const { stripHttp1ConnectionHeaders } = require('./utils')
const http2 = require('http2')
const http2 = require('node:http2')

const {
TimeoutError,
Expand Down
2 changes: 1 addition & 1 deletion test/async-route-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/base-get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/base-querystring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/core-with-path-in-base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/custom-undici-instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const undici = require('undici')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat
const From = require('..')

Expand Down
2 changes: 1 addition & 1 deletion test/disable-request-logging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat
const split = require('split2')

Expand Down
6 changes: 3 additions & 3 deletions test/fastify-multipart-incompatibility.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const Multipart = require('@fastify/multipart')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat
const FormData = require('form-data')

Expand Down
2 changes: 1 addition & 1 deletion test/full-get-test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
6 changes: 3 additions & 3 deletions test/full-https-get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const https = require('https')
const https = require('node:https')
const get = require('simple-get').concat
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const certs = {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
Expand Down
2 changes: 1 addition & 1 deletion test/full-post-extended-content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get')

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-post-stream-core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-post-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-querystring-rewrite-option-complex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
4 changes: 2 additions & 2 deletions test/full-querystring-rewrite-option-function.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat
const querystring = require('querystring')
const querystring = require('node:querystring')

const instance = Fastify()

Expand Down
2 changes: 1 addition & 1 deletion test/full-querystring-rewrite-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-querystring-rewrite-string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-querystring-rewrite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-querystring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-rewrite-body-content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat
const msgpack = require('msgpack5')()

Expand Down
2 changes: 1 addition & 1 deletion test/full-rewrite-body-http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-rewrite-body-to-empty-string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-rewrite-body-to-null.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/full-rewrite-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/get-upstream-http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/get-upstream-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/get-upstream-undici.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/get-with-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/head-with-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat
const semver = require('semver')

Expand Down
4 changes: 2 additions & 2 deletions test/http-agents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const https = require('https')
const http = require('node:http')
const https = require('node:https')
const get = require('simple-get').concat

const instance = Fastify()
Expand Down
2 changes: 1 addition & 1 deletion test/http-global-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const http = require('node:http')
const get = require('simple-get').concat

test('http global agent is used, but not destroyed', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/http-retry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { test } = require('tap')

let retryNum = 1

const target = require('http').createServer(function (req, res) {
const target = require('node:http').createServer(function (req, res) {
if (retryNum % 2 !== 0) {
req.socket.destroy()
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/http2-http2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const h2url = require('h2url')
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const certs = {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
Expand Down
4 changes: 2 additions & 2 deletions test/http2-https.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const got = require('got')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const certs = {
allowHTTP1: true, // fallback support for HTTP1
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
Expand Down
8 changes: 4 additions & 4 deletions test/https-agents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const https = require('https')
const http = require('node:http')
const https = require('node:https')
const get = require('simple-get').concat

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const certs = {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
Expand Down
6 changes: 3 additions & 3 deletions test/https-global-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('..')
const https = require('https')
const https = require('node:https')
const get = require('simple-get').concat

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const certs = {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
Expand Down
Loading