mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
Handle UTF-8 multibyte sequences in node
Content-length header was set to the length of the string, which does not take into account multibyte sequences in UTF-8 strings. Now converts first to a buffer to get the proper length.
This commit is contained in:
@@ -14,10 +14,6 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
config.transformRequest
|
config.transformRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
if (utils.isArrayBuffer(data)) {
|
|
||||||
data = new Buffer(new Uint8Array(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge headers
|
// Merge headers
|
||||||
var headers = utils.merge(
|
var headers = utils.merge(
|
||||||
defaults.headers.common,
|
defaults.headers.common,
|
||||||
@@ -25,8 +21,15 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
config.headers || {}
|
config.headers || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add Content-Length header if data exists
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
if (utils.isArrayBuffer(data)) {
|
||||||
|
data = new Buffer(new Uint8Array(data));
|
||||||
|
} else if (utils.isString(data)) {
|
||||||
|
data = new Buffer(data, 'utf-8');
|
||||||
|
} else {
|
||||||
|
return reject(new Error('Data after transformation must be a string or an ArrayBuffer'));
|
||||||
|
}
|
||||||
|
// Add Content-Length header if data exists
|
||||||
headers['Content-Length'] = data.length;
|
headers['Content-Length'] = data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user