Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xjbieke
axios
提交
b9bb6ae7
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,发现更多精彩内容 >>
提交
b9bb6ae7
编写于
1月 17, 2016
作者:
M
Matt Zabriskie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding support for custom adapters
上级
be241d55
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
6 deletion
+41
-6
README.md
README.md
+9
-3
lib/core/dispatchRequest.js
lib/core/dispatchRequest.js
+12
-3
test/specs/adapter.spec.js
test/specs/adapter.spec.js
+20
-0
未找到文件。
README.md
浏览文件 @
b9bb6ae7
...
...
@@ -167,14 +167,14 @@ These are the available config options for making requests. Only the `url` is re
// `url` is the server URL that will be used for the request
url
:
'
/user
'
,
// `method` is the request method to be used when making the request
method
:
'
get
'
,
// default
// `baseURL` will be prepended to `url` unless `url` is absolute.
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
// to methods of that instance.
baseURL
:
'
https://some-domain.com/api/
'
,
// `method` is the request method to be used when making the request
method
:
'
get
'
,
// default
// `transformRequest` allows changes to the request data before it is sent to the server
// This is only applicable for request methods 'PUT', 'POST', and 'PATCH'
// The last function in the array must return a string or an ArrayBuffer
...
...
@@ -221,6 +221,12 @@ These are the available config options for making requests. Only the `url` is re
// should be made using credentials
withCredentials
:
false
,
// default
// `adapter` allows custom handling of requests which makes testing easier.
// Call `resolve` or `reject` and supply a valid response (see [response docs](#response-api)).
adapter
:
function
(
resolve
,
reject
,
config
)
{
/* ... */
},
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
// This will set an `Authorization` header, overwriting any existing
// `Authorization` custom headers you have set using `headers`.
...
...
lib/core/dispatchRequest.js
浏览文件 @
b9bb6ae7
...
...
@@ -10,12 +10,21 @@
module
.
exports
=
function
dispatchRequest
(
config
)
{
return
new
Promise
(
function
executor
(
resolve
,
reject
)
{
try
{
if
((
typeof
XMLHttpRequest
!==
'
undefined
'
)
||
(
typeof
ActiveXObject
!==
'
undefined
'
))
{
var
adapter
;
if
(
typeof
config
.
adapter
===
'
function
'
)
{
// For custom adapter support
adapter
=
config
.
adapter
;
}
else
if
(
typeof
XMLHttpRequest
!==
'
undefined
'
)
{
// For browsers use XHR adapter
require
(
'
../adapters/xhr
'
)(
resolve
,
reject
,
config
);
adapter
=
require
(
'
../adapters/xhr
'
);
}
else
if
(
typeof
process
!==
'
undefined
'
)
{
// For node use HTTP adapter
require
(
'
../adapters/http
'
)(
resolve
,
reject
,
config
);
adapter
=
require
(
'
../adapters/http
'
);
}
if
(
typeof
adapter
===
'
function
'
)
{
adapter
(
resolve
,
reject
,
config
);
}
}
catch
(
e
)
{
reject
(
e
);
...
...
test/specs/adapter.spec.js
0 → 100644
浏览文件 @
b9bb6ae7
var
axios
=
require
(
'
../../index
'
);
describe
(
'
adapter
'
,
function
()
{
it
(
'
should support custom adapter
'
,
function
(
done
)
{
var
called
=
false
;
axios
({
url
:
'
/foo
'
,
adapter
:
function
(
resolve
,
reject
,
config
)
{
called
=
true
;
}
});
setTimeout
(
function
()
{
expect
(
called
).
toBe
(
true
);
done
();
},
0
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录