|
|
@@ -454,22 +454,24 @@ extension Request: CustomDebugStringConvertible {
|
|
|
func cURLRepresentation() -> String {
|
|
|
var components = ["$ curl -i"]
|
|
|
|
|
|
- guard let request = self.request else {
|
|
|
+ guard let
|
|
|
+ request = self.request,
|
|
|
+ URL = request.URL,
|
|
|
+ host = URL.host
|
|
|
+ else {
|
|
|
return "$ curl command could not be created"
|
|
|
}
|
|
|
|
|
|
- let URL = request.URL
|
|
|
-
|
|
|
if let HTTPMethod = request.HTTPMethod where HTTPMethod != "GET" {
|
|
|
components.append("-X \(HTTPMethod)")
|
|
|
}
|
|
|
|
|
|
if let credentialStorage = self.session.configuration.URLCredentialStorage {
|
|
|
let protectionSpace = NSURLProtectionSpace(
|
|
|
- host: URL!.host!,
|
|
|
- port: URL!.port?.integerValue ?? 0,
|
|
|
- `protocol`: URL!.scheme,
|
|
|
- realm: URL!.host!,
|
|
|
+ host: host,
|
|
|
+ port: URL.port?.integerValue ?? 0,
|
|
|
+ `protocol`: URL.scheme,
|
|
|
+ realm: host,
|
|
|
authenticationMethod: NSURLAuthenticationMethodHTTPBasic
|
|
|
)
|
|
|
|
|
|
@@ -487,7 +489,7 @@ extension Request: CustomDebugStringConvertible {
|
|
|
if session.configuration.HTTPShouldSetCookies {
|
|
|
if let
|
|
|
cookieStorage = session.configuration.HTTPCookieStorage,
|
|
|
- cookies = cookieStorage.cookiesForURL(URL!) where !cookies.isEmpty
|
|
|
+ cookies = cookieStorage.cookiesForURL(URL) where !cookies.isEmpty
|
|
|
{
|
|
|
let string = cookies.reduce("") { $0 + "\($1.name)=\($1.value ?? String());" }
|
|
|
components.append("-b \"\(string.substringToIndex(string.endIndex.predecessor()))\"")
|
|
|
@@ -524,7 +526,7 @@ extension Request: CustomDebugStringConvertible {
|
|
|
components.append("-d \"\(escapedBody)\"")
|
|
|
}
|
|
|
|
|
|
- components.append("\"\(URL!.absoluteString)\"")
|
|
|
+ components.append("\"\(URL.absoluteString)\"")
|
|
|
|
|
|
return components.joinWithSeparator(" \\\n\t")
|
|
|
}
|