|
|
@@ -103,11 +103,12 @@ public enum ParameterEncoding {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- let method = Method.fromRaw(mutableURLRequest.HTTPMethod)
|
|
|
+ let method = Method(rawValue: mutableURLRequest.HTTPMethod)
|
|
|
if method != nil && encodesParametersInURL(method!) {
|
|
|
- let URLComponents = NSURLComponents(URL: mutableURLRequest.URL!, resolvingAgainstBaseURL: false)
|
|
|
- URLComponents.percentEncodedQuery = (URLComponents.query != nil ? URLComponents.query! + "&" : "") + query(parameters!)
|
|
|
- mutableURLRequest.URL = URLComponents.URL
|
|
|
+ if let URLComponents = NSURLComponents(URL: mutableURLRequest.URL!, resolvingAgainstBaseURL: false) {
|
|
|
+ URLComponents.percentEncodedQuery = (URLComponents.query != nil ? URLComponents.query! + "&" : "") + query(parameters!)
|
|
|
+ mutableURLRequest.URL = URLComponents.URL
|
|
|
+ }
|
|
|
} else {
|
|
|
if mutableURLRequest.valueForHTTPHeaderField("Content-Type") == nil {
|
|
|
mutableURLRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
|
|
@@ -241,18 +242,18 @@ public class Manager {
|
|
|
|
|
|
// User-Agent Header; see http://tools.ietf.org/html/rfc7231#section-5.5.3
|
|
|
let userAgent: String = {
|
|
|
- let info = NSBundle.mainBundle().infoDictionary
|
|
|
- let executable: AnyObject = info[kCFBundleExecutableKey] ?? "Unknown"
|
|
|
- let bundle: AnyObject = info[kCFBundleIdentifierKey] ?? "Unknown"
|
|
|
- let version: AnyObject = info[kCFBundleVersionKey] ?? "Unknown"
|
|
|
- let os: AnyObject = NSProcessInfo.processInfo().operatingSystemVersionString ?? "Unknown"
|
|
|
-
|
|
|
- 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
|
|
|
+ if let info = NSBundle.mainBundle().infoDictionary {
|
|
|
+ let executable: AnyObject = info[kCFBundleExecutableKey] ?? "Unknown"
|
|
|
+ let bundle: AnyObject = info[kCFBundleIdentifierKey] ?? "Unknown"
|
|
|
+ let version: AnyObject = info[kCFBundleVersionKey] ?? "Unknown"
|
|
|
+ let os: AnyObject = NSProcessInfo.processInfo().operatingSystemVersionString ?? "Unknown"
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return "Alamofire"
|
|
|
}()
|
|
|
|
|
|
@@ -1235,8 +1236,8 @@ extension Request: DebugPrintable {
|
|
|
components.append("-X \(request.HTTPMethod!)")
|
|
|
}
|
|
|
|
|
|
- if let credentialStorage = session.configuration.URLCredentialStorage {
|
|
|
- let protectionSpace = NSURLProtectionSpace(host: URL.host!, port: URL.port ?? 0, `protocol`: URL.scheme, realm: URL.host, authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
|
|
|
+ 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)
|
|
|
if let credentials = credentialStorage.credentialsForProtectionSpace(protectionSpace)?.values.array {
|
|
|
for credential: NSURLCredential in (credentials as [NSURLCredential]) {
|
|
|
components.append("-u \(credential.user!):\(credential.password!)")
|
|
|
@@ -1276,9 +1277,9 @@ extension Request: DebugPrintable {
|
|
|
}
|
|
|
|
|
|
if let HTTPBody = request.HTTPBody {
|
|
|
- let escapedBody = NSString(data: HTTPBody, encoding: NSUTF8StringEncoding)
|
|
|
- .stringByReplacingOccurrencesOfString("\"", withString: "\\\"")
|
|
|
- components.append("-d \"\(escapedBody)\"")
|
|
|
+ if let escapedBody = NSString(data: HTTPBody, encoding: NSUTF8StringEncoding)?.stringByReplacingOccurrencesOfString("\"", withString: "\\\"") {
|
|
|
+ components.append("-d \"\(escapedBody)\"")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
components.append("\"\(URL.absoluteString!)\"")
|
|
|
@@ -1438,9 +1439,9 @@ extension Request {
|
|
|
|
|
|
// MARK: - Convenience -
|
|
|
|
|
|
-private func URLRequest(method: Method, URLString: URLStringConvertible) -> NSURLRequest {
|
|
|
- let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: URLString.URLString))
|
|
|
- mutableURLRequest.HTTPMethod = method.toRaw()
|
|
|
+private func URLRequest(method: Method, URL: URLStringConvertible) -> NSURLRequest {
|
|
|
+ let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: URL.URLString)!)
|
|
|
+ mutableURLRequest.HTTPMethod = method.rawValue
|
|
|
|
|
|
return mutableURLRequest
|
|
|
}
|