Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xjbieke
axios
提交
18833443
A
axios
项目概览
xjbieke
/
axios
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
axios
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
18833443
编写于
4月 08, 2017
作者:
J
Jeremy Fowler
提交者:
Rubén Norte
4月 08, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support node buffers less than 8192 bytes (#773)
上级
bbfbeff4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
2 deletion
+40
-2
lib/adapters/http.js
lib/adapters/http.js
+4
-2
lib/defaults.js
lib/defaults.js
+1
-0
lib/utils.js
lib/utils.js
+11
-0
test/unit/adapters/http.js
test/unit/adapters/http.js
+24
-0
未找到文件。
lib/adapters/http.js
浏览文件 @
18833443
...
...
@@ -30,13 +30,15 @@ module.exports = function httpAdapter(config) {
}
if
(
data
&&
!
utils
.
isStream
(
data
))
{
if
(
utils
.
isArrayBuffer
(
data
))
{
if
(
utils
.
isBuffer
(
data
))
{
// Nothing to do...
}
else
if
(
utils
.
isArrayBuffer
(
data
))
{
data
=
new
Buffer
(
new
Uint8Array
(
data
));
}
else
if
(
utils
.
isString
(
data
))
{
data
=
new
Buffer
(
data
,
'
utf-8
'
);
}
else
{
return
reject
(
createError
(
'
Data after transformation must be a string, an ArrayBuffer, or a Stream
'
,
'
Data after transformation must be a string, an ArrayBuffer,
a Buffer,
or a Stream
'
,
config
));
}
...
...
lib/defaults.js
浏览文件 @
18833443
...
...
@@ -32,6 +32,7 @@ var defaults = {
normalizeHeaderName
(
headers
,
'
Content-Type
'
);
if
(
utils
.
isFormData
(
data
)
||
utils
.
isArrayBuffer
(
data
)
||
utils
.
isBuffer
(
data
)
||
utils
.
isStream
(
data
)
||
utils
.
isFile
(
data
)
||
utils
.
isBlob
(
data
)
...
...
lib/utils.js
浏览文件 @
18833443
...
...
@@ -18,6 +18,16 @@ function isArray(val) {
return
toString
.
call
(
val
)
===
'
[object Array]
'
;
}
/**
* Determine if a value is a Node Buffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Node Buffer, otherwise false
*/
function
isBuffer
(
val
)
{
return
((
typeof
Buffer
!==
'
undefined
'
)
&&
(
Buffer
.
isBuffer
)
&&
(
Buffer
.
isBuffer
(
val
)));
}
/**
* Determine if a value is an ArrayBuffer
*
...
...
@@ -281,6 +291,7 @@ function extend(a, b, thisArg) {
module
.
exports
=
{
isArray
:
isArray
,
isArrayBuffer
:
isArrayBuffer
,
isBuffer
:
isBuffer
,
isFormData
:
isFormData
,
isArrayBufferView
:
isArrayBufferView
,
isString
:
isString
,
...
...
test/unit/adapters/http.js
浏览文件 @
18833443
...
...
@@ -248,6 +248,30 @@ module.exports = {
});
},
testBuffer
:
function
(
test
)
{
var
buf
=
new
Buffer
(
1024
);
// Unsafe buffer < Buffer.poolSize (8192 bytes)
buf
.
fill
(
'
x
'
);
server
=
http
.
createServer
(
function
(
req
,
res
)
{
test
.
equal
(
req
.
headers
[
'
content-length
'
],
buf
.
length
.
toString
());
req
.
pipe
(
res
);
}).
listen
(
4444
,
function
()
{
axios
.
post
(
'
http://localhost:4444/
'
,
buf
,
{
responseType
:
'
stream
'
}).
then
(
function
(
res
)
{
var
stream
=
res
.
data
;
var
string
=
''
;
stream
.
on
(
'
data
'
,
function
(
chunk
)
{
string
+=
chunk
.
toString
(
'
utf8
'
);
});
stream
.
on
(
'
end
'
,
function
()
{
test
.
equal
(
string
,
buf
.
toString
());
test
.
done
();
});
});
});
},
testHTTPProxy
:
function
(
test
)
{
server
=
http
.
createServer
(
function
(
req
,
res
)
{
res
.
setHeader
(
'
Content-Type
'
,
'
text/html; charset=UTF-8
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录