Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
white49
Alamofire
提交
763747a9
A
Alamofire
项目概览
white49
/
Alamofire
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
Alamofire
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
763747a9
编写于
9月 10, 2016
作者:
C
Christian Noon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored RequestType to RequestTask and moved TaskConvertible in as well.
上级
133aec3b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
44 deletion
+36
-44
Source/Request.swift
Source/Request.swift
+16
-16
Source/SessionManager.swift
Source/SessionManager.swift
+12
-12
Tests/ValidationTests.swift
Tests/ValidationTests.swift
+8
-16
未找到文件。
Source/Request.swift
浏览文件 @
763747a9
...
...
@@ -77,8 +77,11 @@ open class Request {
/// A closure executed when monitoring upload or download progress of a request.
public
typealias
ProgressHandler
=
(
Progress
)
->
Void
enum
RequestType
{
case
data
,
download
,
upload
,
stream
enum
RequestTask
{
case
data
(
TaskConvertible
?,
URLSessionTask
?)
case
download
(
TaskConvertible
?,
URLSessionTask
?)
case
upload
(
TaskConvertible
?,
URLSessionTask
?)
case
stream
(
TaskConvertible
?,
URLSessionTask
?)
}
// MARK: Properties
...
...
@@ -119,25 +122,22 @@ open class Request {
// MARK: Lifecycle
init
(
session
:
URLSession
,
requestType
:
RequestType
,
task
:
URLSessionTask
?
=
nil
,
originalTask
:
TaskConvertible
?
=
nil
,
error
:
Error
?
=
nil
)
{
init
(
session
:
URLSession
,
requestTask
:
RequestTask
,
error
:
Error
?
=
nil
)
{
self
.
session
=
session
self
.
originalTask
=
originalTask
switch
(
task
,
requestType
)
{
case
(
is
URLSessionUploadTask
,
.
upload
),
(
nil
,
.
upload
):
taskDelegate
=
UploadTaskDelegate
(
task
:
task
)
case
(
is
URLSessionDataTask
,
.
data
),
(
nil
,
.
data
):
switch
requestTask
{
case
.
data
(
let
originalTask
,
let
task
):
taskDelegate
=
DataTaskDelegate
(
task
:
task
)
case
(
is
URLSessionDownloadTask
,
.
download
),
(
nil
,
.
download
):
self
.
originalTask
=
originalTask
case
.
download
(
let
originalTask
,
let
task
):
taskDelegate
=
DownloadTaskDelegate
(
task
:
task
)
default
:
self
.
originalTask
=
originalTask
case
.
upload
(
let
originalTask
,
let
task
):
taskDelegate
=
UploadTaskDelegate
(
task
:
task
)
self
.
originalTask
=
originalTask
case
.
stream
(
let
originalTask
,
let
task
):
taskDelegate
=
TaskDelegate
(
task
:
task
)
self
.
originalTask
=
originalTask
}
delegate
.
error
=
error
...
...
Source/SessionManager.swift
浏览文件 @
763747a9
...
...
@@ -253,7 +253,7 @@ open class SessionManager {
let
originalTask
=
DataRequest
.
Requestable
(
urlRequest
:
originalRequest
)
let
task
=
try
originalTask
.
task
(
session
:
session
,
adapter
:
adapter
,
queue
:
queue
)
let
request
=
DataRequest
(
session
:
session
,
requestT
ype
:
.
data
,
task
:
task
,
originalTask
:
originalTask
)
let
request
=
DataRequest
(
session
:
session
,
requestT
ask
:
.
data
(
originalTask
,
task
)
)
delegate
[
task
]
=
request
...
...
@@ -268,7 +268,7 @@ open class SessionManager {
// MARK: Private - Request Implementation
private
func
request
(
failedWith
error
:
Error
)
->
DataRequest
{
let
request
=
DataRequest
(
session
:
session
,
requestT
ype
:
.
data
,
error
:
error
)
let
request
=
DataRequest
(
session
:
session
,
requestT
ask
:
.
data
(
nil
,
nil
)
,
error
:
error
)
if
startRequestsImmediately
{
request
.
resume
()
}
return
request
}
...
...
@@ -372,7 +372,7 @@ open class SessionManager {
{
do
{
let
task
=
try
downloadable
.
task
(
session
:
session
,
adapter
:
adapter
,
queue
:
queue
)
let
request
=
DownloadRequest
(
session
:
session
,
requestT
ype
:
.
download
,
task
:
task
,
originalTask
:
downloadable
)
let
request
=
DownloadRequest
(
session
:
session
,
requestT
ask
:
.
download
(
downloadable
,
task
)
)
request
.
downloadDelegate
.
destination
=
destination
...
...
@@ -387,7 +387,7 @@ open class SessionManager {
}
private
func
download
(
failedWith
error
:
Error
)
->
DownloadRequest
{
let
download
=
DownloadRequest
(
session
:
session
,
requestT
ype
:
.
download
,
error
:
error
)
let
download
=
DownloadRequest
(
session
:
session
,
requestT
ask
:
.
download
(
nil
,
nil
)
,
error
:
error
)
if
startRequestsImmediately
{
download
.
resume
()
}
return
download
}
...
...
@@ -672,24 +672,24 @@ open class SessionManager {
private
func
upload
(
_
uploadable
:
UploadRequest
.
Uploadable
)
->
UploadRequest
{
do
{
let
task
=
try
uploadable
.
task
(
session
:
session
,
adapter
:
adapter
,
queue
:
queue
)
let
request
=
UploadRequest
(
session
:
session
,
requestType
:
.
upload
,
task
:
task
,
originalTask
:
uploadable
)
let
upload
=
UploadRequest
(
session
:
session
,
requestTask
:
.
upload
(
uploadable
,
task
)
)
if
case
let
.
stream
(
inputStream
,
_
)
=
uploadable
{
request
.
delegate
.
taskNeedNewBodyStream
=
{
_
,
_
in
inputStream
}
upload
.
delegate
.
taskNeedNewBodyStream
=
{
_
,
_
in
inputStream
}
}
delegate
[
task
]
=
request
delegate
[
task
]
=
upload
if
startRequestsImmediately
{
request
.
resume
()
}
if
startRequestsImmediately
{
upload
.
resume
()
}
return
request
return
upload
}
catch
{
return
upload
(
failedWith
:
error
)
}
}
private
func
upload
(
failedWith
error
:
Error
)
->
UploadRequest
{
let
upload
=
UploadRequest
(
session
:
session
,
requestT
ype
:
.
upload
,
error
:
error
)
let
upload
=
UploadRequest
(
session
:
session
,
requestT
ask
:
.
upload
(
nil
,
nil
)
,
error
:
error
)
if
startRequestsImmediately
{
upload
.
resume
()
}
return
upload
}
...
...
@@ -732,7 +732,7 @@ open class SessionManager {
private
func
stream
(
_
streamable
:
StreamRequest
.
Streamable
)
->
StreamRequest
{
do
{
let
task
=
try
streamable
.
task
(
session
:
session
,
adapter
:
adapter
,
queue
:
queue
)
let
request
=
StreamRequest
(
session
:
session
,
requestT
ype
:
.
upload
,
task
:
task
,
originalTask
:
streamable
)
let
request
=
StreamRequest
(
session
:
session
,
requestT
ask
:
.
stream
(
streamable
,
task
)
)
delegate
[
task
]
=
request
...
...
@@ -745,7 +745,7 @@ open class SessionManager {
}
private
func
stream
(
failedWith
error
:
Error
)
->
StreamRequest
{
let
stream
=
StreamRequest
(
session
:
session
,
requestT
ype
:
.
stream
,
error
:
error
)
let
stream
=
StreamRequest
(
session
:
session
,
requestT
ask
:
.
stream
(
nil
,
nil
)
,
error
:
error
)
if
startRequestsImmediately
{
stream
.
resume
()
}
return
stream
}
...
...
Tests/ValidationTests.swift
浏览文件 @
763747a9
...
...
@@ -342,13 +342,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
let
originalTask
=
DataRequest
.
Requestable
(
urlRequest
:
originalRequest
)
let
task
=
try
originalTask
.
task
(
session
:
session
,
adapter
:
adapter
,
queue
:
queue
)
let
request
=
MockDataRequest
(
session
:
session
,
requestType
:
.
data
,
task
:
task
,
originalTask
:
originalTask
)
let
request
=
MockDataRequest
(
session
:
session
,
requestTask
:
.
data
(
originalTask
,
task
))
delegate
[
task
]
=
request
...
...
@@ -356,7 +350,9 @@ class ContentTypeValidationTestCase: BaseTestCase {
return
request
}
catch
{
return
DataRequest
(
session
:
session
,
requestType
:
.
data
,
error
:
error
)
let
request
=
DataRequest
(
session
:
session
,
requestTask
:
.
data
(
nil
,
nil
),
error
:
error
)
if
startRequestsImmediately
{
request
.
resume
()
}
return
request
}
}
...
...
@@ -370,13 +366,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
let
originalTask
=
DownloadRequest
.
Downloadable
.
request
(
originalRequest
)
let
task
=
try
originalTask
.
task
(
session
:
session
,
adapter
:
adapter
,
queue
:
queue
)
let
request
=
MockDownloadRequest
(
session
:
session
,
requestType
:
.
download
,
task
:
task
,
originalTask
:
originalTask
)
let
request
=
MockDownloadRequest
(
session
:
session
,
requestTask
:
.
download
(
originalTask
,
task
))
request
.
downloadDelegate
.
destination
=
destination
...
...
@@ -386,7 +376,9 @@ class ContentTypeValidationTestCase: BaseTestCase {
return
request
}
catch
{
return
DownloadRequest
(
session
:
session
,
requestType
:
.
download
,
error
:
error
)
let
download
=
DownloadRequest
(
session
:
session
,
requestTask
:
.
download
(
nil
,
nil
),
error
:
error
)
if
startRequestsImmediately
{
download
.
resume
()
}
return
download
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录