mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
[fix] Encode string payloads as strings even if binary supported (#85)
This reverts commit 44c7aa5, which caused string payloads to be encoded
as binary (so that huge string payloads were needlessly UTF-8-encoded).
Related: https://github.com/socketio/socket.io/issues/2872
This commit is contained in:
committed by
GitHub
parent
36ba01da98
commit
292c00c183
@@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var utf8 = require('./utf8');
|
var utf8 = require('./utf8');
|
||||||
|
var hasBinary = require('has-binary');
|
||||||
var after = require('after');
|
var after = require('after');
|
||||||
var keys = require('./keys');
|
var keys = require('./keys');
|
||||||
|
|
||||||
@@ -217,7 +218,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) {
|
|||||||
supportsBinary = null;
|
supportsBinary = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportsBinary) {
|
if (supportsBinary && hasBinary(packets)) {
|
||||||
return exports.encodePayloadAsBinary(packets, callback);
|
return exports.encodePayloadAsBinary(packets, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,21 +9,3 @@ if (Blob) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require('./base64_object.js');
|
require('./base64_object.js');
|
||||||
|
|
||||||
// General browser only tests
|
|
||||||
var parser = require('../../');
|
|
||||||
var encode = parser.encodePacket;
|
|
||||||
var decode = parser.decodePacket;
|
|
||||||
var encPayload = parser.encodePayload;
|
|
||||||
var decPayload = parser.decodePayload;
|
|
||||||
|
|
||||||
describe('basic functionality', function () {
|
|
||||||
it('should encode string payloads as strings even if binary supported', function (done) {
|
|
||||||
encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) {
|
|
||||||
expect(data).to.be.a('string');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -165,6 +165,15 @@ module.exports = function(parser) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('basic functionality', function () {
|
||||||
|
it('should encode string payloads as strings even if binary supported', function (done) {
|
||||||
|
encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) {
|
||||||
|
expect(data).to.be.a('string');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('encoding and decoding', function () {
|
describe('encoding and decoding', function () {
|
||||||
var seen = 0;
|
var seen = 0;
|
||||||
it('should encode/decode packets', function (done) {
|
it('should encode/decode packets', function (done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user