Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
white49
Alamofire
提交
338955a5
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,发现更多精彩内容 >>
提交
338955a5
编写于
7月 16, 2015
作者:
C
Christian Noon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Audited logic for multiple if let binding and formatting...no functional changes.
上级
bccbf19a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
50 addition
and
32 deletion
+50
-32
Source/Download.swift
Source/Download.swift
+2
-0
Source/Manager.swift
Source/Manager.swift
+2
-2
Source/ParameterEncoding.swift
Source/ParameterEncoding.swift
+2
-2
Source/Request.swift
Source/Request.swift
+12
-4
Source/ResponseSerialization.swift
Source/ResponseSerialization.swift
+8
-10
Source/Upload.swift
Source/Upload.swift
+5
-0
Source/Validation.swift
Source/Validation.swift
+6
-5
Tests/DownloadTests.swift
Tests/DownloadTests.swift
+2
-1
Tests/RequestTests.swift
Tests/RequestTests.swift
+10
-7
Tests/URLProtocolTests.swift
Tests/URLProtocolTests.swift
+1
-1
未找到文件。
Source/Download.swift
浏览文件 @
338955a5
...
...
@@ -43,11 +43,13 @@ extension Manager {
}
let
request
=
Request
(
session
:
self
.
session
,
task
:
downloadTask
)
if
let
downloadDelegate
=
request
.
delegate
as?
Request
.
DownloadTaskDelegate
{
downloadDelegate
.
downloadTaskDidFinishDownloadingToURL
=
{
session
,
downloadTask
,
URL
in
return
destination
(
URL
,
downloadTask
.
response
as!
NSHTTPURLResponse
)
}
}
self
.
delegate
[
request
.
delegate
.
task
]
=
request
.
delegate
if
self
.
startRequestsImmediately
{
...
...
Source/Manager.swift
浏览文件 @
338955a5
...
...
@@ -72,8 +72,9 @@ public class Manager {
var
mutableUserAgent
=
NSMutableString
(
string
:
"
\(
executable
)
/
\(
bundle
)
(
\(
version
)
; OS
\(
os
)
)"
)
as
CFMutableString
let
transform
=
NSString
(
string
:
"Any-Latin; Latin-ASCII; [:^ASCII:] Remove"
)
as
CFString
if
CFStringTransform
(
mutableUserAgent
,
nil
,
transform
,
0
)
==
1
{
return
mutableUserAgent
as
NSString
as!
String
return
mutableUserAgent
as
String
}
}
...
...
@@ -291,7 +292,6 @@ public class Manager {
taskDidComplete
(
session
,
task
,
error
)
}
else
if
let
delegate
=
self
[
task
]
{
delegate
.
URLSession
(
session
,
task
:
task
,
didCompleteWithError
:
error
)
self
[
task
]
=
nil
}
}
...
...
Source/ParameterEncoding.swift
浏览文件 @
338955a5
...
...
@@ -103,8 +103,7 @@ public enum ParameterEncoding {
}
}
let
method
=
Method
(
rawValue
:
mutableURLRequest
.
HTTPMethod
)
if
let
method
=
method
where
encodesParametersInURL
(
method
)
{
if
let
method
=
Method
(
rawValue
:
mutableURLRequest
.
HTTPMethod
)
where
encodesParametersInURL
(
method
)
{
if
let
URLComponents
=
NSURLComponents
(
URL
:
mutableURLRequest
.
URL
!
,
resolvingAgainstBaseURL
:
false
)
{
URLComponents
.
percentEncodedQuery
=
(
URLComponents
.
percentEncodedQuery
.
map
{
$0
+
"&"
}
??
""
)
+
query
(
parameters
!
)
mutableURLRequest
.
URL
=
URLComponents
.
URL
...
...
@@ -118,6 +117,7 @@ public enum ParameterEncoding {
}
case
.
JSON
:
let
options
=
NSJSONWritingOptions
.
allZeros
if
let
data
=
NSJSONSerialization
.
dataWithJSONObject
(
parameters
!
,
options
:
options
,
error
:
&
error
)
{
mutableURLRequest
.
setValue
(
"application/json"
,
forHTTPHeaderField
:
"Content-Type"
)
mutableURLRequest
.
HTTPBody
=
data
...
...
Source/Request.swift
浏览文件 @
338955a5
...
...
@@ -403,6 +403,7 @@ extension Request: Printable {
/// The textual representation used when written to an output stream, which includes the HTTP method and URL, as well as the response status code if a response has been received.
public
var
description
:
String
{
var
components
:
[
String
]
=
[]
if
let
HTTPMethod
=
self
.
request
.
HTTPMethod
{
components
.
append
(
HTTPMethod
)
}
...
...
@@ -430,7 +431,14 @@ extension Request: DebugPrintable {
}
if
let
credentialStorage
=
self
.
session
.
configuration
.
URLCredentialStorage
{
let
protectionSpace
=
NSURLProtectionSpace
(
host
:
URL
!.
host
!
,
port
:
URL
!.
port
?
.
integerValue
??
0
,
`
protocol
`:
URL
!.
scheme
!
,
realm
:
URL
!.
host
!
,
authenticationMethod
:
NSURLAuthenticationMethodHTTPBasic
)
let
protectionSpace
=
NSURLProtectionSpace
(
host
:
URL
!.
host
!
,
port
:
URL
!.
port
?
.
integerValue
??
0
,
`
protocol
`:
URL
!.
scheme
!
,
realm
:
URL
!.
host
!
,
authenticationMethod
:
NSURLAuthenticationMethodHTTPBasic
)
if
let
credentials
=
credentialStorage
.
credentialsForProtectionSpace
(
protectionSpace
)?
.
values
.
array
{
for
credential
:
NSURLCredential
in
(
credentials
as!
[
NSURLCredential
])
{
components
.
append
(
"-u
\(
credential
.
user
!
)
:
\(
credential
.
password
!
)
"
)
...
...
@@ -446,9 +454,9 @@ extension Request: DebugPrintable {
// See https://github.com/CocoaPods/swift/issues/24
#if !os(OSX)
if
self
.
session
.
configuration
.
HTTPShouldSetCookies
{
if
let
cookieStorage
=
self
.
session
.
configuration
.
HTTPCookieStorage
,
cookie
s
=
cookieStorage
.
cookiesForURL
(
URL
!
)
as?
[
NSHTTPCookie
]
where
!
cookies
.
isEmpty
if
let
cookie
Storage
=
self
.
session
.
configuration
.
HTTPCookieStorage
,
cookies
=
cookieStorage
.
cookiesForURL
(
URL
!
)
as?
[
NSHTTPCookie
]
where
!
cookies
.
isEmpty
{
let
string
=
cookies
.
reduce
(
""
){
$0
+
"
\(
$1
.
name
)
=
\(
$1
.
value
??
String
()
)
;"
}
components
.
append
(
"-b
\"\(
string
.
substringToIndex
(
string
.
endIndex
.
predecessor
())
)\"
"
)
...
...
Source/ResponseSerialization.swift
浏览文件 @
338955a5
...
...
@@ -38,10 +38,8 @@ extension Request {
return
(
nil
,
nil
)
}
if
encoding
==
nil
{
if
let
encodingName
=
response
?
.
textEncodingName
{
encoding
=
CFStringConvertEncodingToNSStringEncoding
(
CFStringConvertIANACharSetNameToEncoding
(
encodingName
))
}
if
let
encodingName
=
response
?
.
textEncodingName
where
encoding
==
nil
{
encoding
=
CFStringConvertEncodingToNSStringEncoding
(
CFStringConvertIANACharSetNameToEncoding
(
encodingName
))
}
let
string
=
NSString
(
data
:
data
!
,
encoding
:
encoding
??
NSISOLatin1StringEncoding
)
...
...
@@ -59,9 +57,9 @@ extension Request {
:returns: The request.
*/
public
func
responseString
(
encoding
:
NSStringEncoding
?
=
nil
,
completionHandler
:
(
NSURLRequest
,
NSHTTPURLResponse
?,
String
?,
NSError
?)
->
Void
)
->
Self
{
return
response
(
serializer
:
Request
.
stringResponseSerializer
(
encoding
:
encoding
)
,
completionHandler
:
{
request
,
response
,
string
,
error
in
return
response
(
serializer
:
Request
.
stringResponseSerializer
(
encoding
:
encoding
)
)
{
request
,
response
,
string
,
error
in
completionHandler
(
request
,
response
,
string
as?
String
,
error
)
}
)
}
}
}
...
...
@@ -97,9 +95,9 @@ extension Request {
:returns: The request.
*/
public
func
responseJSON
(
options
:
NSJSONReadingOptions
=
.
AllowFragments
,
completionHandler
:
(
NSURLRequest
,
NSHTTPURLResponse
?,
AnyObject
?,
NSError
?)
->
Void
)
->
Self
{
return
response
(
serializer
:
Request
.
JSONResponseSerializer
(
options
:
options
)
,
completionHandler
:
{
request
,
response
,
JSON
,
error
in
return
response
(
serializer
:
Request
.
JSONResponseSerializer
(
options
:
options
)
)
{
request
,
response
,
JSON
,
error
in
completionHandler
(
request
,
response
,
JSON
,
error
)
}
)
}
}
}
...
...
@@ -135,8 +133,8 @@ extension Request {
:returns: The request.
*/
public
func
responsePropertyList
(
options
:
NSPropertyListReadOptions
=
0
,
completionHandler
:
(
NSURLRequest
,
NSHTTPURLResponse
?,
AnyObject
?,
NSError
?)
->
Void
)
->
Self
{
return
response
(
serializer
:
Request
.
propertyListResponseSerializer
(
options
:
options
)
,
completionHandler
:
{
request
,
response
,
plist
,
error
in
return
response
(
serializer
:
Request
.
propertyListResponseSerializer
(
options
:
options
)
)
{
request
,
response
,
plist
,
error
in
completionHandler
(
request
,
response
,
plist
,
error
)
}
)
}
}
}
Source/Upload.swift
浏览文件 @
338955a5
...
...
@@ -46,15 +46,18 @@ extension Manager {
dispatch_sync
(
self
.
queue
)
{
uploadTask
=
self
.
session
.
uploadTaskWithStreamedRequest
(
request
)
}
HTTPBodyStream
=
stream
}
let
request
=
Request
(
session
:
self
.
session
,
task
:
uploadTask
)
if
HTTPBodyStream
!=
nil
{
request
.
delegate
.
taskNeedNewBodyStream
=
{
_
,
_
in
return
HTTPBodyStream
}
}
self
.
delegate
[
request
.
delegate
.
task
]
=
request
.
delegate
if
self
.
startRequestsImmediately
{
...
...
@@ -127,6 +130,7 @@ extension Manager {
*/
public
func
upload
(
method
:
Method
,
_
URLString
:
URLStringConvertible
,
headers
:
[
String
:
String
]?
=
nil
,
data
:
NSData
)
->
Request
{
let
mutableURLRequest
=
URLRequest
(
method
,
URLString
,
headers
:
headers
)
return
upload
(
mutableURLRequest
,
data
:
data
)
}
...
...
@@ -160,6 +164,7 @@ extension Manager {
*/
public
func
upload
(
method
:
Method
,
_
URLString
:
URLStringConvertible
,
headers
:
[
String
:
String
]?
=
nil
,
stream
:
NSInputStream
)
->
Request
{
let
mutableURLRequest
=
URLRequest
(
method
,
URLString
,
headers
:
headers
)
return
upload
(
mutableURLRequest
,
stream
:
stream
)
}
...
...
Source/Validation.swift
浏览文件 @
338955a5
...
...
@@ -72,9 +72,12 @@ extension Request {
let
subtype
:
String
init
?(
_
string
:
String
)
{
let
components
=
string
.
stringByTrimmingCharactersInSet
(
NSCharacterSet
.
whitespaceAndNewlineCharacterSet
())
.
substringToIndex
(
string
.
rangeOfString
(
";"
)?
.
endIndex
??
string
.
endIndex
)
.
componentsSeparatedByString
(
"/"
)
let
components
=
string
.
stringByTrimmingCharactersInSet
(
NSCharacterSet
.
whitespaceAndNewlineCharacterSet
())
.
substringToIndex
(
string
.
rangeOfString
(
";"
)?
.
endIndex
??
string
.
endIndex
)
.
componentsSeparatedByString
(
"/"
)
if
let
type
=
components
.
first
,
if
let
type
=
components
.
first
,
subtype
=
components
.
last
{
self
.
type
=
type
...
...
@@ -110,9 +113,7 @@ extension Request {
responseMIMEType
=
MIMEType
(
responseContentType
)
{
for
contentType
in
acceptableContentTypes
{
if
let
acceptableMIMEType
=
MIMEType
(
contentType
)
where
acceptableMIMEType
.
matches
(
responseMIMEType
)
{
if
let
acceptableMIMEType
=
MIMEType
(
contentType
)
where
acceptableMIMEType
.
matches
(
responseMIMEType
)
{
return
true
}
}
...
...
Tests/DownloadTests.swift
浏览文件 @
338955a5
...
...
@@ -198,7 +198,8 @@ class DownloadResponseTestCase: BaseTestCase {
}
}
if
let
lastByteValue
=
byteValues
.
last
,
if
let
lastByteValue
=
byteValues
.
last
,
lastProgressValue
=
progressValues
.
last
{
let
byteValueFractionalCompletion
=
Double
(
lastByteValue
.
totalBytes
)
/
Double
(
lastByteValue
.
totalBytesExpected
)
...
...
Tests/RequestTests.swift
浏览文件 @
338955a5
...
...
@@ -98,7 +98,7 @@ class RequestResponseTestCase: BaseTestCase {
error
=
responseError
expectation
.
fulfill
()
}
}
waitForExpectationsWithTimeout
(
self
.
defaultTimeout
,
handler
:
nil
)
...
...
@@ -162,7 +162,8 @@ class RequestResponseTestCase: BaseTestCase {
}
}
if
let
lastByteValue
=
byteValues
.
last
,
if
let
lastByteValue
=
byteValues
.
last
,
lastProgressValue
=
progressValues
.
last
{
let
byteValueFractionalCompletion
=
Double
(
lastByteValue
.
totalBytes
)
/
Double
(
lastByteValue
.
totalBytesExpected
)
...
...
@@ -232,7 +233,8 @@ class RequestResponseTestCase: BaseTestCase {
}
}
if
let
lastByteValue
=
byteValues
.
last
,
if
let
lastByteValue
=
byteValues
.
last
,
lastProgressValue
=
progressValues
.
last
{
let
byteValueFractionalCompletion
=
Double
(
lastByteValue
.
totalBytes
)
/
Double
(
lastByteValue
.
totalBytesExpected
)
...
...
@@ -283,17 +285,17 @@ class RequestDescriptionTestCase: BaseTestCase {
class
RequestDebugDescriptionTestCase
:
BaseTestCase
{
// MARK: Properties
let
manager
:
Alamofire
.
Manager
=
{
let
manager
=
Alamofire
.
Manager
(
configuration
:
NSURLSessionConfiguration
.
defaultSessionConfiguration
())
let
manager
:
Manager
=
{
let
manager
=
Manager
(
configuration
:
NSURLSessionConfiguration
.
defaultSessionConfiguration
())
manager
.
startRequestsImmediately
=
false
return
manager
}()
let
managerDisallowingCookies
:
Alamofire
.
Manager
=
{
let
managerDisallowingCookies
:
Manager
=
{
let
configuration
=
NSURLSessionConfiguration
.
defaultSessionConfiguration
()
configuration
.
HTTPShouldSetCookies
=
false
let
manager
=
Alamofire
.
Manager
(
configuration
:
configuration
)
let
manager
=
Manager
(
configuration
:
configuration
)
manager
.
startRequestsImmediately
=
false
return
manager
...
...
@@ -355,6 +357,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
NSHTTPCookieName
:
"foo"
,
NSHTTPCookieValue
:
"bar"
,
]
let
cookie
=
NSHTTPCookie
(
properties
:
properties
)
!
manager
.
session
.
configuration
.
HTTPCookieStorage
?
.
setCookie
(
cookie
)
...
...
Tests/URLProtocolTests.swift
浏览文件 @
338955a5
...
...
@@ -149,7 +149,7 @@ class URLProtocolTestCase: BaseTestCase {
error
=
responseError
expectation
.
fulfill
()
}
}
waitForExpectationsWithTimeout
(
self
.
defaultTimeout
,
handler
:
nil
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录