Skip to content

Commit

Permalink
dep(server)!: bump [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Sep 2, 2023
1 parent 14b2099 commit 3a16322
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 47 deletions.
21 changes: 11 additions & 10 deletions tests/server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const http = require('http');
const stringify = require('json-stringify-safe');
const Busboy = require('busboy');
const busboy = require('busboy');
const { Iconv } = require('iconv');

const port = process.env.PORT || 5000;
Expand All @@ -15,26 +15,27 @@ function parseMultipartForm (req, res, finishCb) {

const fields = {};
const files = {};
const busboy = new Busboy({ headers: req.headers });
const bb = busboy({ headers: req.headers });

busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
bb.on('file', (name, file, info) => {
const { filename } = info;
const currentFile = { size: 0 };

file.on('data', function (data) {
currentFile.name = filename;
currentFile.size += data.length;
});

file.on('end', function () {
file.on('close', function () {
files.file = currentFile;
});
});

busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
bb.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
fields[fieldname] = val;
});

busboy.on('finish', function () {
bb.on('close', function () {
console.log(stringify({ fields, files }));

// This is needed due to this bug: https://github.com/mscdex/busboy/issues/73
Expand All @@ -43,15 +44,15 @@ function parseMultipartForm (req, res, finishCb) {
}
});

busboy.on('error', function (err) {
bb.on('error', function (err) {
console.error(`error: ${err}: ${JSON.stringify(err)}`);
errorOccured = true;

res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end(`Could not parse multipart form: ${err}\n`);
});

req.pipe(busboy);
req.pipe(bb);
}

function respondWithParsedForm (req, res, parseResultObj) {
Expand Down Expand Up @@ -115,7 +116,7 @@ http.createServer(function (req, res) {
req.on('data', function (chunk) {
body += chunk;
if (body.length > DIRECT_UPLOAD_LIMIT) {
req.connection.destroy();
req.socket.destroy();
}
});

Expand Down Expand Up @@ -150,7 +151,7 @@ http.createServer(function (req, res) {
res.end('404\n');
}

console.log(req.connection.remoteAddress + ' ' + req.method + ' ' + req.url + ' ' + res.statusCode + ' ' + req.headers['user-agent']);
console.log(req.socket.remoteAddress + ' ' + req.method + ' ' + req.url + ' ' + res.statusCode + ' ' + req.headers['user-agent']);
}).listen(port, '0.0.0.0');

console.log('Server running on ' + port);
67 changes: 31 additions & 36 deletions tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"dependencies": {
"busboy": "^0.3.1",
"busboy": "^1.6.0",
"forever": "^4.0.3",
"iconv": "^3.0.1",
"json-stringify-safe": "^5.0.1"
Expand Down

0 comments on commit 3a16322

Please sign in to comment.