diff --git a/Source/Request+AlamofireImage.swift b/Source/Request+AlamofireImage.swift index cbe280f3..ca9019b6 100644 --- a/Source/Request+AlamofireImage.swift +++ b/Source/Request+AlamofireImage.swift @@ -33,6 +33,27 @@ import Cocoa #endif extension Request { + static var acceptableImageContentTypes: Set = [ + "image/tiff", + "image/jpeg", + "image/gif", + "image/png", + "image/ico", + "image/x-icon", + "image/bmp", + "image/x-bmp", + "image/x-xbitmap", + "image/x-win-bitmap" + ] + + /** + Adds the content types specified to the list of acceptable images content types for validation. + + - parameter contentTypes: The additional content types. + */ + public class func addAcceptableImageContentTypes(contentTypes: Set) { + Request.acceptableImageContentTypes.unionInPlace(contentTypes) + } // MARK: - iOS and watchOS @@ -195,20 +216,7 @@ extension Request { return true } - let acceptableContentTypes: Set = [ - "image/tiff", - "image/jpeg", - "image/gif", - "image/png", - "image/ico", - "image/x-icon", - "image/bmp", - "image/x-bmp", - "image/x-xbitmap", - "image/x-win-bitmap" - ] - - if let mimeType = response?.MIMEType where acceptableContentTypes.contains(mimeType) { + if let mimeType = response?.MIMEType where Request.acceptableImageContentTypes.contains(mimeType) { return true } diff --git a/Tests/RequestTests.swift b/Tests/RequestTests.swift index b1b1ea93..98afc430 100644 --- a/Tests/RequestTests.swift +++ b/Tests/RequestTests.swift @@ -21,11 +21,40 @@ // THE SOFTWARE. import Alamofire -import AlamofireImage +@testable import AlamofireImage import Foundation import XCTest class RequestTestCase: BaseTestCase { + var acceptableImageContentTypes: Set! + + // MARK: - Setup and Teardown + + override func setUp() { + super.setUp() + acceptableImageContentTypes = Request.acceptableImageContentTypes + } + + override func tearDown() { + super.tearDown() + Request.acceptableImageContentTypes = acceptableImageContentTypes + } + + // MARK: - Image Content Type Tests + + func testThatAddingAcceptableImageContentTypesInsertsThemIntoTheGlobalList() { + // Given + let contentTypes: Set = ["image/jpg", "binary/octet-stream"] + + // When + let beforeCount = Request.acceptableImageContentTypes.count + Request.addAcceptableImageContentTypes(contentTypes) + let afterCount = Request.acceptableImageContentTypes.count + + // Then + XCTAssertEqual(beforeCount, 10, "before count should be 10") + XCTAssertEqual(afterCount, 12, "after count should be 12") + } // MARK: - Image Serialization Tests