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 @fastify/busboy #2211

Merged
merged 8 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/fetch/body.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Busboy = require('busboy')
const Busboy = require('@fastify/busboy')
const util = require('../core/util')
const {
ReadableStreamFrom,
Expand Down Expand Up @@ -385,9 +385,8 @@ function bodyMixinMethods (instance) {
let busboy

try {
busboy = Busboy({
headers,
defParamCharset: 'utf8'
busboy = new Busboy({
headers
})
} catch (err) {
throw new DOMException(`${err}`, 'AbortError')
Expand All @@ -396,8 +395,7 @@ function bodyMixinMethods (instance) {
busboy.on('field', (name, value) => {
responseFormData.append(name, value)
})
busboy.on('file', (name, value, info) => {
const { filename, encoding, mimeType } = info
busboy.on('file', (name, value, filename, encoding, mimeType) => {
const chunks = []

if (encoding === 'base64' || encoding.toLowerCase() === 'base64') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@
]
},
"dependencies": {
"busboy": "^1.6.0"
"@fastify/busboy": "^1.2.1"
}
}
2 changes: 1 addition & 1 deletion test/fetch/client-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ test('busboy emit error', async (t) => {
const formRaw = await tempRes.text()

const server = createServer((req, res) => {
res.setHeader('content-type', 'multipart/form-data; boundary=wrongboundary')
res.setHeader('content-type', 'multipart/form-data')
res.write(formRaw)
res.end()
})
Expand Down
4 changes: 2 additions & 2 deletions test/node-fetch/utils/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const http = require('http')
const zlib = require('zlib')
const { once } = require('events')
const newBusboy = require('busboy')
const Busboy = require('@fastify/busboy')

module.exports = class TestServer {
constructor () {
Expand Down Expand Up @@ -435,7 +435,7 @@ module.exports = class TestServer {
if (p === '/multipart') {
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
const busboy = newBusboy({ headers: request.headers })
const busboy = new Busboy({ headers: request.headers })
let body = ''
busboy.on('file', async (fieldName, file, fileName) => {
body += `${fieldName}=${fileName}`
Expand Down
4 changes: 2 additions & 2 deletions test/utils/formdata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const busboy = require('busboy')
const Busboy = require('@fastify/busboy')

function parseFormDataString (
body,
Expand All @@ -9,7 +9,7 @@ function parseFormDataString (
fields: []
}

const bb = busboy({
const bb = new Busboy({
headers: {
'content-type': contentType
}
Expand Down