Skip to content
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
4 changes: 2 additions & 2 deletions lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ class Gateway extends EventEmitter {
let nameRegex = /name="([^"]*)"/;
let contentTypeRegex = /Content-Type: ([^\s]+)*/

let formString = '\r\n' + formBuffer.toString()
let formString = '\r\n' + formBuffer.toString('latin1')
let params = formString
.split(this.__getMultipartFormBoundary__([contentType, ...contentTypeParameters].join(';')))
.slice(1, -1)
Expand All @@ -633,7 +633,7 @@ class Gateway extends EventEmitter {
}
break;
default:
params[key] = Buffer.from(value);
params[key] = Buffer.from(value, 'latin1');
break;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "functionscript",
"version": "2.3.5",
"version": "2.3.7",
"description": "An API gateway and framework for turning functions into web services",
"author": "Keith Horwood <keithwhor@gmail.com>",
"main": "index.js",
Expand Down
7 changes: 7 additions & 0 deletions tests/gateway/functions/buffer_reflect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @param {buffer} bufferParam
* @returns {buffer} mybuf
*/
module.exports = async (bufferParam) => {
return bufferParam;
};
34 changes: 33 additions & 1 deletion tests/gateway/tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const http = require('http');
const zlib = require('zlib');
const fs = require('fs')
const FormData = require('form-data');
const {Gateway, FunctionParser} = require('../../index.js');

Expand Down Expand Up @@ -1331,7 +1332,7 @@ module.exports = (expect) => {
});

it('Should handle multipart/form-data with buffer', done => {
const fs = require('fs')

let pkgJson = fs.readFileSync(process.cwd() + '/package.json')

let form = new FormData();
Expand Down Expand Up @@ -1433,6 +1434,37 @@ module.exports = (expect) => {
})
});

it('Should handle multipart/form-data with a png', done => {

let image = fs.readFileSync(process.cwd() + '/tests/gateway/www/fs-wordmark.png');

let form = new FormData();
form.append('bufferParam', image);

form.submit(`http://${HOST}:${PORT}/buffer_reflect`, (err, response) => {

expect(err).to.not.exist;
expect(response.statusCode).to.equal(200);

let body = [];
response.on('readable', function() {
body.push(response.read());
});

response.on('end', function() {
let result = Buffer.concat(body);
expect(image.equals(result)).to.equal(true);
done();
});

response.on('err', function(err) {
expect(err).to.not.exist;
done();
})

})
});

it('Should reject an object that doesn\'t map to Schema', done => {
request('POST', {}, '/schema_rejection/', {
obj: {
Expand Down