Răsfoiți Sursa

Merge branch 'master' into swift3

# Conflicts:
#	Sources/ImageDownloader.swift
onevcat 9 ani în urmă
părinte
comite
7d4396af6e
4 a modificat fișierele cu 36 adăugiri și 13 ștergeri
  1. 0 13
      CHANGELOG.md
  2. 10 0
      README.md
  3. 7 0
      Sources/ImageDownloader.swift
  4. 19 0
      Tests/KingfisherTests/ImageDownloaderTests.swift

+ 0 - 13
CHANGELOG.md

@@ -15,19 +15,6 @@
 
 ---
 
-## [2.4.2 - Optional Welcome](https://github.com/onevcat/Kingfisher/releases/tag/2.4.2) (2016-07-10)
-
-#### Add
-* Accept `nil` as valid URL parameter for image view's extension methods.
-
-#### Fix
-* The completion handler of image view setting method will not be called any more if `self` is released.
-* Improve empty task so some performance improvment could be achieved.
-* Remove SwiftLint since it keeps adding new rules but without a back compatible support. It makes the users confusing when using a different version of SwiftLint.
-* Removed Implicit Unwrapping of CacheType that caused crashes if the image is not cached.
-
----
-
 ## [2.4.1 - Force Transition](https://github.com/onevcat/Kingfisher/releases/tag/2.4.1) (2016-05-10)
 
 #### Add

+ 10 - 0
README.md

@@ -73,7 +73,17 @@ use_frameworks!
 
 pod 'Kingfisher', '~> 2.4'
 ```
+If your CocoaPods Version > 1.0.0, you needs add Target name like this:
 
+```ruby
+source 'https://github.com/CocoaPods/Specs.git'
+platform :ios, '8.0'
+use_frameworks!
+
+target ‘<Your Target Name>’ do
+    pod 'Kingfisher', '~> 2.4'
+end
+```
 Then, run the following command:
 
 ``` bash

+ 7 - 0
Sources/ImageDownloader.swift

@@ -85,6 +85,7 @@ The error code.
 public enum KingfisherError: Int {
     case badData = 10000
     case notModified = 10001
+    case InvalidStatusCode = 10002
     case invalidURL = 20000
 }
 
@@ -367,6 +368,12 @@ class ImageDownloaderSessionHandler: NSObject, URLSessionDataDelegate, Authentic
     */
     internal func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: (URLSession.ResponseDisposition) -> Void) {
         
+        // If server response is not 200,201 or 304, inform the callback handler with InvalidStatusCode error.
+        // InvalidStatusCode error has userInfo which include statusCode and localizedString.
+        if let statusCode = (response as? NSHTTPURLResponse)?.statusCode, let URL = dataTask.originalRequest?.URL where statusCode != 200 && statusCode != 201 && statusCode != 304 {
+            callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidStatusCode.rawValue, userInfo: ["statusCode": statusCode, "localizedStringForStatusCode": NSHTTPURLResponse.localizedStringForStatusCode(statusCode)]), imageURL: URL, originalData: nil)
+        }
+        
         completionHandler(Foundation.URLSession.ResponseDisposition.allow)
     }
     

+ 19 - 0
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -160,8 +160,26 @@ class ImageDownloaderTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
     
+    func testServerInvalidStatusCode() {
+        let expectation = expectationWithDescription("wait for response which has invalid status code")
+        
+        let URLString = testKeys[0]
+        stubRequest("GET", URLString).andReturn(404).withBody(testImageData)
+        
+        downloader.downloadImageWithURL(NSURL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+            
+        }) { (image, error, imageURL, data) -> () in
+            XCTAssertNotNil(error, "There should be an error since server returning 404")
+            XCTAssertEqual(error!.code, KingfisherError.InvalidStatusCode.rawValue, "The error should be InvalidStatusCode.")
+            XCTAssertEqual(error!.userInfo["statusCode"]! as? Int, 404, "The error should be InvalidStatusCode.")
+            expectation.fulfill()
+        }
+        waitForExpectationsWithTimeout(5, handler: nil)
+    }
+    
     // Since we could not receive one challage, no test for trusted hosts currently.
     // See http://stackoverflow.com/questions/27065372/why-is-a-https-nsurlsession-connection-only-challenged-once-per-domain for more.
+    /* Temporarily disables since the target site is offline. See https://github.com/onevcat/Kingfisher/issues/365
     func testSSLCertificateValidation() {
         LSNocilla.sharedInstance().stop()
         
@@ -183,6 +201,7 @@ class ImageDownloaderTests: XCTestCase {
             LSNocilla.sharedInstance().start()
         }
     }
+    */
     
     func testDownloadResultErrorAndRetry() {
         let expectation = self.expectation(description: "wait for downloading error")