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

dep(server)!: bump [email protected], [email protected], [email protected] & rebuilt package-lock #370

Merged
merged 3 commits into from
Sep 5, 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
25 changes: 13 additions & 12 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 || 5001;
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) {
file.on('data', (data) => {
currentFile.name = filename;
currentFile.size += data.length;
});

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

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

busboy.on('finish', function () {
bb.on('close', () => {
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);
Loading
Loading