Skip to content

Commit

Permalink
Merge pull request #40 from cmdrsabre/master
Browse files Browse the repository at this point in the history
added interface for additional http headers
  • Loading branch information
ramy-kfoury authored Feb 14, 2017
2 parents 78ec01e + 31e6f16 commit 58fe8fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Library/MapleBacon/MapleBacon/ImageDownloadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public final class ImageDownloadOperation: Operation {
fileprivate let progress: Progress = Progress()

public var completionHandler: ImageDownloaderCompletion?

public var httpAdditionalHeaders: [AnyHashable: Any]?

public convenience init(imageURL: URL) {
self.init(imageURL: imageURL, delegate: nil)
Expand All @@ -33,8 +35,10 @@ public final class ImageDownloadOperation: Operation {

public override func start() {
let sessionConfiguration = URLSessionConfiguration.default
sessionConfiguration.httpAdditionalHeaders = httpAdditionalHeaders
session = Foundation.URLSession(configuration: sessionConfiguration, delegate: self,
delegateQueue: OperationQueue.main)

resumeDownload()
}

Expand Down
3 changes: 3 additions & 0 deletions Library/MapleBacon/MapleBacon/ImageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public final class ImageManager {
fileprivate let downloadQueue = OperationQueue()
fileprivate var downloadsInProgress = [URL: ImageDownloadOperation]()

public var httpAdditionalHeaders: [AnyHashable: Any]?

deinit {
downloadQueue.cancelAllOperations()
}
Expand All @@ -23,6 +25,7 @@ public final class ImageManager {
} else {
if downloadsInProgress[url] == nil {
let downloadOperation = ImageDownloadOperation(imageURL: url)
downloadOperation.httpAdditionalHeaders = httpAdditionalHeaders
downloadOperation.qualityOfService = .userInitiated
downloadOperation.completionHandler = downloadHandlerWithStorage(url, cacheScaled: cacheScaled,
imageView: imageView, storage: storage,
Expand Down

0 comments on commit 58fe8fa

Please sign in to comment.