GithubHelp home page GithubHelp logo

fastify / busboy Goto Github PK

View Code? Open in Web Editor NEW
68.0 6.0 17.0 548 KB

A streaming parser for HTML form data for node.js

License: MIT License

JavaScript 92.38% TypeScript 7.38% Batchfile 0.24%
fastify-fork fastify-library

busboy's Introduction

busboy

Build Status Coverage Status js-standard-style Security Responsible Disclosure

NPM version NPM downloads

Description

A Node.js module for parsing incoming HTML form data.

This is an officially supported fork by fastify organization of the amazing library originally created by Brian White, aimed at addressing long-standing issues with it.

Benchmark (Mean time for 500 Kb payload, 2000 cycles, 1000 cycle warmup):

Library Version Mean time in nanoseconds (less is better)
busboy 0.3.1 340114
@fastify/busboy 1.0.0 270984

Changelog since busboy 0.31.

Requirements

Install

npm i @fastify/busboy

Examples

  • Parsing (multipart) with default options:
const http = require('node:http');
const { inspect } = require('node:util');
const Busboy = require('busboy');

http.createServer((req, res) => {
  if (req.method === 'POST') {
    const busboy = new Busboy({ headers: req.headers });
    busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
      console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`);
      file.on('data', data => {
        console.log(`File [${fieldname}] got ${data.length} bytes`);
      });
      file.on('end', () => {
        console.log(`File [${fieldname}] Finished`);
      });
    });
    busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
      console.log(`Field [${fieldname}]: value: ${inspect(val)}`);
    });
    busboy.on('finish', () => {
      console.log('Done parsing form!');
      res.writeHead(303, { Connection: 'close', Location: '/' });
      res.end();
    });
    req.pipe(busboy);
  } else if (req.method === 'GET') {
    res.writeHead(200, { Connection: 'close' });
    res.end(`<html><head></head><body>
               <form method="POST" enctype="multipart/form-data">
                <input type="text" name="textfield"><br>
                <input type="file" name="filefield"><br>
                <input type="submit">
              </form>
            </body></html>`);
  }
}).listen(8000, () => {
  console.log('Listening for requests');
});

// Example output, using http://nodejs.org/images/ryan-speaker.jpg as the file:
//
// Listening for requests
// File [filefield]: filename: ryan-speaker.jpg, encoding: binary
// File [filefield] got 11971 bytes
// Field [textfield]: value: 'testing! :-)'
// File [filefield] Finished
// Done parsing form!
  • Save all incoming files to disk:
const http = require('node:http');
const path = require('node:path');
const os = require('node:os');
const fs = require('node:fs');

const Busboy = require('busboy');

http.createServer(function(req, res) {
  if (req.method === 'POST') {
    const busboy = new Busboy({ headers: req.headers });
    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
      var saveTo = path.join(os.tmpdir(), path.basename(fieldname));
      file.pipe(fs.createWriteStream(saveTo));
    });
    busboy.on('finish', function() {
      res.writeHead(200, { 'Connection': 'close' });
      res.end("That's all folks!");
    });
    return req.pipe(busboy);
  }
  res.writeHead(404);
  res.end();
}).listen(8000, function() {
  console.log('Listening for requests');
});
  • Parsing (urlencoded) with default options:
const http = require('node:http');
const { inspect } = require('node:util');

const Busboy = require('busboy');

http.createServer(function(req, res) {
  if (req.method === 'POST') {
    const busboy = new Busboy({ headers: req.headers });
    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
      console.log('File [' + fieldname + ']: filename: ' + filename);
      file.on('data', function(data) {
        console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
      });
      file.on('end', function() {
        console.log('File [' + fieldname + '] Finished');
      });
    });
    busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
      console.log('Field [' + fieldname + ']: value: ' + inspect(val));
    });
    busboy.on('finish', function() {
      console.log('Done parsing form!');
      res.writeHead(303, { Connection: 'close', Location: '/' });
      res.end();
    });
    req.pipe(busboy);
  } else if (req.method === 'GET') {
    res.writeHead(200, { Connection: 'close' });
    res.end('<html><head></head><body>\
               <form method="POST">\
                <input type="text" name="textfield"><br />\
                <select name="selectfield">\
                  <option value="1">1</option>\
                  <option value="10">10</option>\
                  <option value="100">100</option>\
                  <option value="9001">9001</option>\
                </select><br />\
                <input type="checkbox" name="checkfield">Node.js rules!<br />\
                <input type="submit">\
              </form>\
            </body></html>');
  }
}).listen(8000, function() {
  console.log('Listening for requests');
});

// Example output:
//
// Listening for requests
// Field [textfield]: value: 'testing! :-)'
// Field [selectfield]: value: '9001'
// Field [checkfield]: value: 'on'
// Done parsing form!

API

Busboy is a Writable stream

Busboy (special) events

  • file(< string >fieldname, < ReadableStream >stream, < string >filename, < string >transferEncoding, < string >mimeType) - Emitted for each new file form field found. transferEncoding contains the 'Content-Transfer-Encoding' value for the file stream. mimeType contains the 'Content-Type' value for the file stream.

    • Note: if you listen for this event, you should always handle the stream no matter if you care about the file contents or not (e.g. you can simply just do stream.resume(); if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about any incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards files and parts limits).
    • If a configured file size limit was reached, stream will both have a boolean property truncated (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.
    • The property bytesRead informs about the number of bytes that have been read so far.
  • field(< string >fieldname, < string >value, < boolean >fieldnameTruncated, < boolean >valueTruncated, < string >transferEncoding, < string >mimeType) - Emitted for each new non-file field found.

  • partsLimit() - Emitted when specified parts limit has been reached. No more 'file' or 'field' events will be emitted.

  • filesLimit() - Emitted when specified files limit has been reached. No more 'file' events will be emitted.

  • fieldsLimit() - Emitted when specified fields limit has been reached. No more 'field' events will be emitted.

Busboy methods

  • (constructor)(< object >config) - Creates and returns a new Busboy instance.

    • The constructor takes the following valid config settings:

      • headers - object - These are the HTTP headers of the incoming request, which are used by individual parsers.

      • autoDestroy - boolean - Whether this stream should automatically call .destroy() on itself after ending. (Default: false).

      • highWaterMark - integer - highWaterMark to use for this Busboy instance (Default: WritableStream default).

      • fileHwm - integer - highWaterMark to use for file streams (Default: ReadableStream default).

      • defCharset - string - Default character set to use when one isn't defined (Default: 'utf8').

      • preservePath - boolean - If paths in the multipart 'filename' field shall be preserved. (Default: false).

      • isPartAFile - function - Use this function to override the default file detection functionality. It has following parameters:

        • fieldName - string The name of the field.

        • contentType - string The content-type of the part, e.g. text/plain, image/jpeg, application/octet-stream

        • fileName - string The name of a file supplied by the part.

        (Default: (fieldName, contentType, fileName) => (contentType === 'application/octet-stream' || fileName !== undefined))

      • limits - object - Various limits on incoming data. Valid properties are:

        • fieldNameSize - integer - Max field name size (in bytes) (Default: 100 bytes).

        • fieldSize - integer - Max field value size (in bytes) (Default: 1 MiB, which is 1024 x 1024 bytes).

        • fields - integer - Max number of non-file fields (Default: Infinity).

        • fileSize - integer - For multipart forms, the max file size (in bytes) (Default: Infinity).

        • files - integer - For multipart forms, the max number of file fields (Default: Infinity).

        • parts - integer - For multipart forms, the max number of parts (fields + files) (Default: Infinity).

        • headerPairs - integer - For multipart forms, the max number of header key=>value pairs to parse Default: 2000

        • headerSize - integer - For multipart forms, the max size of a multipart header Default: 81920.

    • The constructor can throw errors:

      • Busboy expected an options-Object. - Busboy expected an Object as first parameters.

      • Busboy expected an options-Object with headers-attribute. - The first parameter is lacking of a headers-attribute.

      • Limit $limit is not a valid number - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number.

      • Unsupported Content-Type. - The Content-Type isn't one Busboy can parse.

      • Missing Content-Type-header. - The provided headers don't include Content-Type at all.

busboy's People

Contributors

amir-arad avatar asnowfix avatar avianflu avatar dependabot[bot] avatar eomm avatar fdawgs avatar gurgunday avatar gwicke avatar kemitchell avatar khafradev avatar kibertoad avatar linusu avatar mscdex avatar puskin94 avatar rommelandrea avatar ryan1234 avatar samal-rasmussen avatar samypesse avatar sebmaster avatar silverwind avatar uzlopak avatar zekth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

busboy's Issues

Malformed boundary does not throw

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

X

Plugin version

X

Node.js version

20

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Latest

Description

I want to merge @fastify/busboy into undici, but a specific test will not currently pass:

test('busboy emit error', async (t) => {
  t.plan(1)
  const formData = new FormData()
  formData.append('field1', 'value1')

  const tempRes = new Response(formData)
  const formRaw = await tempRes.text()

  const server = createServer((req, res) => {
    res.setHeader('content-type', 'multipart/form-data; boundary=wrongboundary')
    res.write(formRaw)
    res.end()
  })
  t.teardown(server.close.bind(server))

  const listen = promisify(server.listen.bind(server))
  await listen(0)

  const res = await fetch(`http://localhost:${server.address().port}`)
  await t.rejects(res.formData(), 'Unexpected end of multipart data')
})

Busboy ignores this input rather than throwing for malformed boundary

I found within the code a part that should throw in this case (if I'm not mistaken), but it's not working in practice

I will take a look at this myself, but if anyone could help, it would be highly appreciated

Steps to Reproduce

Run this test after replacing busboy with @fastify/busboy in undici:

test('busboy emit error', async (t) => {
  t.plan(1)
  const formData = new FormData()
  formData.append('field1', 'value1')

  const tempRes = new Response(formData)
  const formRaw = await tempRes.text()

  const server = createServer((req, res) => {
    res.setHeader('content-type', 'multipart/form-data; boundary=wrongboundary')
    res.write(formRaw)
    res.end()
  })
  t.teardown(server.close.bind(server))

  const listen = promisify(server.listen.bind(server))
  await listen(0)

  const res = await fetch(`http://localhost:${server.address().port}`)
  await t.rejects(res.formData(), 'Unexpected end of multipart data')
})

Expected Behavior

Test should pass

Video Uploads are extremely slow

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I am not sure what may be the issue but when uploading short length videos of less than 2MB the video upload is blazing fast.

However, the moment I tried to upload a 20MB video, the time it takes before busboy starts to process the video is so so long.

Here is my code snippet:


busboy.on('file', async function (fieldname, file, filename, encoding, mimetype) {

             console.log("Video Reached Busboy"); //This happened very fast

            if (!unProcessedFilePaths.includes(filename)) {

                let fileType = await FileService.getFileType(filename);
                let transferredBytes = 0;

                console.log(`On Data about to be called`); 

                file.on('data', async (data) => {
                    console.log(`On Data is been called`);   //This is called only after about 2mins for a 20MB video. Weird

Please advise.

Thank you.

How to break out of busboy and send back a regular response

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hi there! Thank you so much for porting this amazing library. Probably the only award winning chunked file uploads library in the entire NodeJS ecosystem. I migrated to this library just now and it's been an amazing journey already!!!!

I however have a few questions about breaking out of busboy to send a regular response back to the client.

Here is my code:


 static async createNewPost(req, res) {
        let busboy = new Busboy({
            headers: req.headers,
            highWaterMark: 2 * 1024 * 1024,
            limits: {
                fileSize: Constants.PlatformData.MAXIMUM_ALLOWED_FILE_UPLOAD_SIZE,
            },
        });
        let apiKey = req.header(Strings.API_KEY);
        let badRequestError = Preconditions.checkNotNull({ apiKey});
        if (badRequestError) {
         // I wish to send back a response here like this:
         return res.status(404).send({   //But this line seems to be throwing a Server Request Interrupted error. How can I fix it?
            statusCode: 404,
            message: "You provided an invalid api key"
        });
        }
   }

But breaking out to send a response like the above is throwing Server Request Interrupted error.

Any insight on how best to break out of busboy and send back a regular response like the above will be truly appreciated.

Thank you.

Reported dicer to snyk

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I reported dicer to snyk. They already wrote me back and requested further information. I assume that in few days dicer will be marked with having a security issue.

100 % test coverage

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

We should have 100% test coverage

Motivation

No response

Example

No response

Handle empty filenames as fields instead of files

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

When crafting browser requests it doesn't seem possible to leave out the filename in case you want to send a blob:

const body = new FormData();
body.append('json', new Blob(['{"foo":"bar"}'], {type: 'application/json'}));
fetch('/test', {method: 'POST', body});

Uses "glob" as filename.

const body = new FormData();
body.append('json', new Blob(['{"foo":"bar"}'], {type: 'application/json'}), '');
fetch('/test', {method: 'POST', body});

Uses "" as filename.

const body = new FormData();
body.append('json', new Blob(['{"foo":"bar"}'], {type: 'application/json'}), null);
fetch('/test', {method: 'POST', body});

Uses "null" as filename.

Therefore such requests are handled as file because of this undefined check:
https://github.com/mscdex/busboy/blob/master/lib/types/multipart.js#L174

Is it reasonable to also accept parts with empty filenames as fields? Wouldn't a real file always have a filename?

I think that this could be seen as breaking change.

A minor change would be adding an option for a custom filtering handler which let the user decide whether a specific part should be handled as file or field.

remove fork reference

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I think we should remove the fork reference.

Migrate the ecosystem

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Now that 1.0.0 is out, we should go through https://www.npmjs.com/package/busboy and submit migration PRs to projects that have non-insignificant amount of users.

Done: fastify-multipart, multer.

Migrate photofinish benchmarks to tinybench, improve benchmarks

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Migrate the photofinisch benchmarks to tinybench. Also check if we can migrate the dicer benchmarks to tinybench. I mean those who just output the MB/s.

Motivation

No response

Example

No response

Improve test coverage

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

We have around 50% code coverage.
We can do better.

Help needed for uploading files

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hello, i'm trying to upload files on my nextjs 14.0.4 app with fastify/busboy, however, while the files upload in the right repo, with the right name and right extension, they are unsuable "Not a JPEG file: starts with 0xef 0xbf", exemple with an jpeg file. I double checked the files are fine. It's my first nextjs app, any help would be greatly aprreciated. Thanks for your time.

import { PrismaClient } from '@prisma/client';
const Busboy = require('@fastify/busboy');
import fs from 'fs';
import path from 'path';
import os from 'os';

const prisma = new PrismaClient();

export const createRessource = async (req, res) => {
try {

const bb = new Busboy({ headers: req.headers, limits: { fileSize: 3000000 }, highWaterMark: undefined });
const formData = {};

bb.on('file', (fieldname, file, filename, encoding, mimetype) => {
  console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`);

  const uniqueFilename = `${fieldname}-${Date.now()}-${path.basename(filename)}`;
  const saveTo = path.join('public', 'images', uniqueFilename);
  const buffers = [];

  file.on('data', (data) => {
    buffers.push(data);
    console.log(`File [${filename}] got ${data.length} bytes`);
  });

  file.on('end', () => {
    console.log(`File [${filename}] Finished`);
    const fileData = Buffer.concat(buffers);
    fs.writeFileSync(saveTo, fileData);
    console.log(`File [${filename}] save to [${saveTo}]`);
    formData[fieldname] = {
      filename: uniqueFilename,
      path: saveTo,
      mimetype: mimetype
    };
  });
});

bb.on('field', (fieldname, val) => {
  console.log(`Field [${fieldname}]: value: ${val}`);
  formData[fieldname] = val;
});

bb.on('finish', async () => {
  console.log('Done parsing form!');

  const { titre, contenu, categorieName, visibilite, filefield } = formData;
  const fileInfo = formData[filefield];

  const currentDate = new Date();

  const newRessource = await prisma.t_ressource.create({
    data: {
      ressource_titre: titre,
      ressource_date: currentDate,
      ressource_contenu: contenu,
      id_categorie: categorieName,
      ressource_media: fileInfo,
      ressource_visibilite: visibilite,
    },
  });

  console.log('Ressource créée:', newRessource);
  console.log('Nom du fichier :', fileInfo);

  res.json({
    success: true,
    message: 'Ressource créée avec succès',
    ressource: newRessource,
  });
});

bb.on('error', (err) => {
  console.error('Erreur lors du traitement du formulaire :', err);
  res.status(500).json({
    success: false,
    message: 'Erreur lors du traitement du formulaire',
  });
});

req.once('data', (chunk) => {
  bb.write(chunk);
});

bb.end(req.body);

} catch (error) {
console.error('Erreur lors de la création de la ressource:', error);
res.status(500).json({
success: false,
message: 'Erreur lors de la création de la ressource',
});
} finally {
await prisma.$disconnect();
}
}

My Environment

node version: v20.11.0
fastify version: >=2.0.0
os: Linux
Nextjs 14.0.4, prisma.

mscdex Updated his projects

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

mscdex updated his packages. I did a benchmark and our fork is slightly faster than his busboy. Maybe we should take a look at his code changes and check if we can apply those changes to our fork.

Streamsearch refactoring for better performance

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

We should consider to refactor the StreamSearch-component. Our benchmark is actually working with in memory, and I think that 4 GB/s is kind of slow. If it would be filesystem, than I guess, 4 GB/s is good, but in-memory seems to be slow. Maybe I am just expecting too much?

I wrote the unit tests to actually write a drop-in replacement. I started to write it multiple times, but I didnt succeeded, unfortunately.
I guess, we could do alot of that searching per character with Buffer.indexOf and other "modern" node functionality.

Maybe you @kibertoad or @mcollina could write a high performance one? I thought of @mcollina because he also wrote split2 npm package, which does something similar.

Screenshot from 2021-11-29 13-47-53

Motivation

No response

Example

No response

'node_modules/@fastify/busboy/lib/utils.js': TypeError: Value is not an object: undefined

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

See in firebase-admin SDK (messaging)

Plugin version

See in firebase-admin SDK (messaging)

Node.js version

MongoDB Atlas Trigger : JS SDK Version: 3.18.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

No idea sorry

Description

I don't know NodeJS at all sorry, but i am using the firebase_admin package that is actually using your package as a dependency.

I have no clue about it but since they don't answer to my issue there.
I am making an issue here so perhaps you could tell me what is happening :

'http' module: FunctionError: failed to execute source for 'node_modules/@fastify/busboy/lib/main.js': FunctionError: failed to execute source for 'node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js': FunctionError: failed to execute source for 'node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js': FunctionError: failed to execute source for 'node_modules/@fastify/busboy/lib/utils.js': TypeError: Value is not an object: undefined
	at node_modules/@fastify/busboy/lib/utils.js:23:27(322)

	at require (native)
	at node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:15:24(29)

	at require (native)
	at node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:19:28(39)

	at require (native)
	at node_modules/@fastify/busboy/lib/main.js:28:21(44)

I must specify that this error is not impacting my service, but i am having multiple errors in my Atlas trigger because of this.

Steps to Reproduce

You will find all the detail in the mentioned issue.

Expected Behavior

This error could be more explicit (with the wrong value logged for example).

I would especially really appreciate you tell me what can be wrong here or answer directly in the Firebase repo with what's wrong in their code please.

Fails to parse request stream on bun

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

2.1.0

Plugin version

No response

Node.js version

Bun v1.0.15

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.0

Description

This is related to

I understand if bun support is beyond the scope of this project, but I did do some exploring. From what I can tell the root issue is in this library (or bun!).

What I did was wrote the failing request stream to a file. Then in the root of this project I stream that file into busboy and listen for fields and files. When running with node the file and field are found. When running with bun neither events are emitted.

At the root

'use strict'

const fs = require('fs')
const Busboy = require('.')

const busboy = new Busboy({
  headers: {
    'content-type': 'multipart/form-data; boundary=__X_PAW_BOUNDARY__'
  }
})

busboy.on('field', function (key) {
  console.log('field found', key)
})
busboy.on('file', function (fieldname, stream) {
  console.log('file found', fieldname)

  stream.on('end', () => {
    console.log(`File [${fieldname}] Finished`)
  })
})
busboy.on('finish', function () {
  console.log('finished')
})

// stream request dump to busboy
const readable = fs.createReadStream('./test/dump')
readable.pipe(busboy)

The request dump: https://drive.google.com/file/d/19_y4fy5pwi6_xDYblHhSp0bEIMhNSiYS/view?usp=share_link

node busboy-test.js
bun busboy-test.js

Steps to Reproduce

Run the above script

Expected Behavior

No response

Potential Code improvements in other forks

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Code we should check for validity and potential source for new features

pirxpilot/dicer@93922c0
pirxpilot/dicer@fb36ab9
pirxpilot/dicer@69c09a6
pirxpilot/dicer@a6aa5d8
peterfirst/dicer@f4d1aa6
jonruttan/dicer@9a62b87
jonruttan/dicer@60ea418
chrishiestand/busboy@e7a1384
mnmly/busboy@9c71052
rangyf/busboy@ce1ff1b

Motivation

No response

Example

No response

Demand support ESM

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

// please support import
import Busboy from "@fastify/busboy"
// lib/main.js
// add the line
module.exports.default = Busboy

Need to get full header

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

I need to get the full raw headers from each field, as is, without any modification.

Motivation

You do strip out quite a bit, and leave many things behind.

headers that are not known to you gets discarded, headers meta ;key=value pair gets discarded too.

And some things even get modified as you apply to lowercase here and there.

I need to parse the headers on my own, so it would be good if you could send the headers as a 2D iterable array
(as one header could appair twice)

// x-forwared-for: 192.168.0.1
// x-forwared-for: 192.168.0.2

headers = new Headers([
  ['x-forwared-for', '192.168.0.1'],
  ['x-forwared-for', '192.168.0.2']
])
headers.get('x-forwared-for') // 192.168.0.1, 192.168.0.2

Example

the arguments length is getting out of control cuz they are so many now. and i don't need all of them... An object would be better...

-   busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
+   busboy.on('field', (field) => {
      console.log(`Field [${field.fieldname}]: value: ${field.val}`);
    });

so that i could do:

busboy.on('field', (field) => {
  console.assert(Array.isArray(field.headers))
  Object.fromEntries(field.headers)
  new Headers(field.headers)
})

Add Input validation

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Wie should Check If the options passed to busboy are valid and if not throw TypeErrors.

mscdex/busboy#207

If you agree @kibertoad I would prepare a PR

Motivation

No response

Example

No response

Is Content-Encoding handled gracefully?

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

mscdex/busboy#150
expressjs/multer#976

It was reported, that busboy breaks "silently" if payload is sent as gzip encoded. I dont think that we should handle gzip or any other content-encoding in busboy.

But we should check what "silently" means. Does it crash the server? Does it not throw any error?
For this we would need some payload to test with. @wenjunche can you please provide a complete payload to see what is happening?
Also we should consider to document that busboy does not handle content-encoding and use the "workaround" as solution .

Uploading an excel document is giving an error

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.10.2

Plugin version

1.2.0

Node.js version

18.12.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04.01

Description

I have a nestjs project using fastify.
Today I updated all my dependencies, and as a result it seems the upload of an excel file gives this error:

[Nest] 74345  - 01/06/2023, 5:37:32 PM   ERROR [ExceptionsHandler] Premature close
Error: Premature close
    at new NodeError (node:internal/errors:393:5)
    at onclose (node:internal/streams/end-of-stream:142:30)
    at processTicksAndRejections (node:internal/process/task_queues:77:11)

Some digging brought me to this transient dependency of busboy. pinning this to 1.1.0 fixes my problem, but it might be something you want to look into.

if it helps, the mimetype is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Steps to Reproduce

This is using nestje configured to use fastify

  1. make an endpoint to recieve a file
  2. send an excel file via a multipart form

Expected Behavior

I expect the file to arrive in the endpoint to be processed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.