Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Alamofire/Alamofire into …
Browse files Browse the repository at this point in the history
…podspec

* 'master' of https://github.com/Alamofire/Alamofire:
  [Issue Alamofire#230] Making response object example initializer failable
  Fixing optional textLabel property on cells
  Adding missing forced unwrap in test
  [Issue Alamofire#226] Fixing optional cookie entry in cURL output
  Fixing possible exception when force unwrapping optional header properties
  • Loading branch information
fabiopelosin committed Nov 27, 2014
2 parents caa66f7 + b5d6f58 commit 96bcf0c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Example/DetailViewController.swift
Expand Up @@ -104,14 +104,14 @@ class DetailViewController: UITableViewController {
let field = self.headers.keys.array.sorted(<)[indexPath.row]
let value = self.headers[field]

cell.textLabel.text = field
cell.textLabel?.text = field
cell.detailTextLabel!.text = value

return cell
case .Body:
let cell = self.tableView.dequeueReusableCellWithIdentifier("Body") as UITableViewCell

cell.textLabel.text = self.body
cell.textLabel?.text = self.body

return cell
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -498,7 +498,7 @@ Generics can be used to provide automatic, type-safe response object serializati

```swift
@objc public protocol ResponseObjectSerializable {
init(response: NSHTTPURLResponse, representation: AnyObject)
init?(response: NSHTTPURLResponse, representation: AnyObject)
}

extension Alamofire.Request {
Expand All @@ -514,7 +514,7 @@ extension Alamofire.Request {
}

return response(serializer: serializer, completionHandler: { (request, response, object, error) in
completionHandler(request, response, object as? T, error)
completionHandler(request, response, object, error)
})
}
}
Expand All @@ -525,7 +525,7 @@ final class User: ResponseObjectSerializable {
let username: String
let name: String

required init(response: NSHTTPURLResponse, representation: AnyObject) {
required init?(response: NSHTTPURLResponse, representation: AnyObject) {
self.username = response.URL!.lastPathComponent
self.name = representation.valueForKeyPath("name") as String
}
Expand Down
30 changes: 17 additions & 13 deletions Source/Alamofire.swift
Expand Up @@ -1257,27 +1257,31 @@ extension Request: DebugPrintable {
if let cookieStorage = session.configuration.HTTPCookieStorage {
if let cookies = cookieStorage.cookiesForURL(URL) as? [NSHTTPCookie] {
if !cookies.isEmpty {
let string = cookies.reduce(""){ $0 + "\($1.name)=\($1.value);" }
let string = cookies.reduce(""){ $0 + "\($1.name)=\($1.value ?? String());" }
components.append("-b \"\(string.substringToIndex(string.endIndex.predecessor()))\"")
}
}
}

for (field, value) in request.allHTTPHeaderFields! {
switch field {
case "Cookie":
continue
default:
components.append("-H \"\(field): \(value)\"")
if request.allHTTPHeaderFields != nil {
for (field, value) in request.allHTTPHeaderFields! {
switch field {
case "Cookie":
continue
default:
components.append("-H \"\(field): \(value)\"")
}
}
}

for (field, value) in session.configuration.HTTPAdditionalHeaders! {
switch field {
case "Cookie":
continue
default:
components.append("-H \"\(field): \(value)\"")
if session.configuration.HTTPAdditionalHeaders != nil {
for (field, value) in session.configuration.HTTPAdditionalHeaders! {
switch field {
case "Cookie":
continue
default:
components.append("-H \"\(field): \(value)\"")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/DownloadTests.swift
Expand Up @@ -68,7 +68,7 @@ class AlamofireDownloadResponseTestCase: XCTestCase {
XCTAssertEqual(filteredContents.count, 1, "should have one file in Documents")

let file = filteredContents.first as NSURL
XCTAssertEqual(file.lastPathComponent, "\(numberOfLines)", "filename should be \(numberOfLines)")
XCTAssertEqual(file.lastPathComponent!, "\(numberOfLines)", "filename should be \(numberOfLines)")

if let data = NSData(contentsOfURL: file) {
XCTAssertGreaterThan(data.length, 0, "data length should be non-zero")
Expand Down
24 changes: 24 additions & 0 deletions Tests/RequestTests.swift
Expand Up @@ -127,4 +127,28 @@ class AlamofireRequestDebugDescriptionTestCase: XCTestCase {
XCTAssert(request.debugDescription.rangeOfString("-d \"{\\\"foo\\\":\\\"bar\\\"}\"") != nil)
XCTAssert(components.last! == "\"\(URL)\"", "URL component should be equal")
}

func testPOSTRequestWithCookieDebugDescription() {
let URL = "http://httpbin.org/post"

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()

let properties = [
NSHTTPCookieDomain: "httpbin.org",
NSHTTPCookiePath: "/post",
NSHTTPCookieName: "foo",
NSHTTPCookieValue: "bar",
]
let cookie = NSHTTPCookie(properties: properties)!
configuration.HTTPCookieStorage?.setCookie(cookie)

let manager = Alamofire.Manager(configuration: configuration)
let request = manager.request(.POST, URL)
let components = cURLCommandComponents(request)

XCTAssert(components[0..<3] == ["$", "curl", "-i"], "components should be equal")
XCTAssert(components[3..<5] == ["-X", "POST"], "command should contain explicit -X flag")
XCTAssert(components[5..<7] == ["-b", "\"foo=bar\""], "command should contain -b flag")
XCTAssert(components.last! == "\"\(URL)\"", "URL component should be equal")
}
}

0 comments on commit 96bcf0c

Please sign in to comment.