Skip to content

Commit

Permalink
Merge pull request #3741 from idandagan1/master
Browse files Browse the repository at this point in the history
Replace new Buffer()
  • Loading branch information
hueniverse authored Mar 2, 2018
2 parents 916808f + 74f5236 commit 8e367bb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const internals = {
'start',
'stop'
],
badRequestResponse: new Buffer('HTTP/1.1 400 Bad Request\r\n\r\n', 'ascii')
badRequestResponse: Buffer.from('HTTP/1.1 400 Bad Request\r\n\r\n', 'ascii')
};


Expand Down
4 changes: 2 additions & 2 deletions test/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('payload', () => {

it('returns 413 with response when payload is not consumed', async () => {

const payload = new Buffer(10 * 1024 * 1024).toString();
const payload = Buffer.alloc(10 * 1024 * 1024).toString();

const server = Hapi.server();
server.route({ method: 'POST', path: '/', options: { handler: () => null, payload: { maxBytes: 1024 * 1024 } } });
Expand Down Expand Up @@ -487,7 +487,7 @@ describe('payload', () => {

it('signals connection close when payload is unconsumed', async () => {

const payload = new Buffer(1024);
const payload = Buffer.alloc(1024);
const server = Hapi.server();
server.route({ method: 'POST', path: '/', options: { handler: () => 'ok', payload: { maxBytes: 1024, output: 'stream', parse: false } } });

Expand Down
2 changes: 1 addition & 1 deletion test/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('Response', () => {

const handler = (request, h) => {

return h.response('ok').header('set-cookie', new Buffer(decodeURIComponent('%E0%B4%8Aset-cookie:%20foo=bar')));
return h.response('ok').header('set-cookie', Buffer.from(decodeURIComponent('%E0%B4%8Aset-cookie:%20foo=bar')));
};

const server = Hapi.server();
Expand Down
6 changes: 3 additions & 3 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ describe('Server', () => {
const res1 = await server.inject('/');
expect(res1.statusCode).to.equal(401);

const res2 = await server.inject({ method: 'GET', url: '/', headers: { authorization: 'Basic ' + (new Buffer('john:12345', 'utf8')).toString('base64') } });
const res2 = await server.inject({ method: 'GET', url: '/', headers: { authorization: 'Basic ' + (Buffer.from('john:12345', 'utf8')).toString('base64') } });
expect(res2.statusCode).to.equal(200);
expect(res2.result).to.equal('authenticated!');
});
Expand Down Expand Up @@ -1520,7 +1520,7 @@ describe('Server', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await new Promise((resolve) => Zlib.gzip(new Buffer(data), (ignoreErr, compressed) => resolve(compressed)));
const zipped = await new Promise((resolve) => Zlib.gzip(Buffer.from(data), (ignoreErr, compressed) => resolve(compressed)));
const { res, payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip, deflate, test' }, payload: data });
expect(res.headers['content-encoding']).to.equal('test');
expect(payload.toString()).to.equal(zipped.toString());
Expand Down Expand Up @@ -2654,7 +2654,7 @@ internals.plugins = {
throw Boom.badRequest('Bad HTTP authentication header format', 'Basic');
}

const credentialsParts = new Buffer(parts[1], 'base64').toString().split(':');
const credentialsParts = Buffer.from(parts[1], 'base64').toString().split(':');
if (credentialsParts.length !== 2) {
throw Boom.badRequest('Bad header internal syntax', 'Basic');
}
Expand Down
2 changes: 1 addition & 1 deletion test/toolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Toolkit', () => {

const handler = (request, h) => {

return h.response(new Buffer('Tada1')).code(299);
return h.response(Buffer.from('Tada1')).code(299);
};

const server = Hapi.server();
Expand Down
28 changes: 14 additions & 14 deletions test/transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe('transmission', () => {
it('returns an JSONP response when response is a buffer', async () => {

const server = Hapi.server();
server.route({ method: 'GET', path: '/', options: { jsonp: 'callback', handler: () => new Buffer('value') } });
server.route({ method: 'GET', path: '/', options: { jsonp: 'callback', handler: () => Buffer.from('value') } });

const res = await server.inject('/?callback=me');
expect(res.payload).to.equal('/**/me(value);');
Expand Down Expand Up @@ -767,7 +767,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));

const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip' }, payload: data });
expect(payload.toString()).to.equal(zipped.toString());
Expand All @@ -783,7 +783,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'gzip' } });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
Expand Down Expand Up @@ -824,7 +824,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const deflated = await internals.compress('deflate', new Buffer(data));
const deflated = await internals.compress('deflate', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'deflate' }, payload: data });
expect(payload.toString()).to.equal(deflated.toString());
await server.stop();
Expand All @@ -838,7 +838,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const deflated = await internals.compress('deflate', new Buffer(data));
const deflated = await internals.compress('deflate', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'deflate' } });
expect(payload.toString()).to.equal(deflated.toString());
await server.stop();
Expand All @@ -852,7 +852,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5' }, payload: data });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
Expand All @@ -866,7 +866,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5' } });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
Expand All @@ -880,7 +880,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const deflated = await internals.compress('deflate', new Buffer(data));
const deflated = await internals.compress('deflate', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'deflate;q=1, gzip;q=0.5' }, payload: data });
expect(payload.toString()).to.equal(deflated.toString());
await server.stop();
Expand All @@ -894,7 +894,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const deflated = await internals.compress('deflate', new Buffer(data));
const deflated = await internals.compress('deflate', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'deflate;q=1, gzip;q=0.5' } });
expect(payload.toString()).to.equal(deflated.toString());
await server.stop();
Expand All @@ -908,7 +908,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'deflate, gzip' }, payload: data });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
Expand All @@ -922,7 +922,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'deflate, gzip' } });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
Expand All @@ -943,7 +943,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const err1 = await expect(Wreck.get(uri, { headers: { 'accept-encoding': 'gzip' } })).to.reject();
expect(err1.data.payload.toString()).to.equal(zipped.toString());

Expand All @@ -968,7 +968,7 @@ describe('transmission', () => {
await server.start();

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const err1 = await expect(Wreck.get(uri, { headers: { 'accept-encoding': 'gzip' } })).to.reject();
expect(err1.data.payload.toString()).to.equal(zipped.toString());

Expand Down Expand Up @@ -1013,7 +1013,7 @@ describe('transmission', () => {
it('returns a gzip response when forced by the handler', async () => {

const data = '{"test":"true"}';
const zipped = await internals.compress('gzip', new Buffer(data));
const zipped = await internals.compress('gzip', Buffer.from(data));
const server = Hapi.server({ compression: { minBytes: 1 } });
server.route({ method: 'POST', path: '/', handler: (request, h) => h.response(zipped).type('text/plain').header('content-encoding', 'gzip') });
await server.start();
Expand Down

0 comments on commit 8e367bb

Please sign in to comment.