提交 c0201fd4 编写于 作者: M Matt Zabriskie

Merge pull request #13 from mathbruyen/utf8_content_length

Handle UTF-8 multibyte sequences in node
......@@ -14,10 +14,6 @@ module.exports = function httpAdapter(resolve, reject, config) {
config.transformRequest
);
if (utils.isArrayBuffer(data)) {
data = new Buffer(new Uint8Array(data));
}
// Merge headers
var headers = utils.merge(
defaults.headers.common,
......@@ -25,8 +21,15 @@ module.exports = function httpAdapter(resolve, reject, config) {
config.headers || {}
);
// Add Content-Length header if data exists
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册