Kingfisher Documentation

Protocol Image​Download​Redirect​Handler

public protocol ImageDownloadRedirectHandler  

Represents and wraps a method for modifying request during an image download request redirection.

%173 ImageDownloadRedirectHandler ImageDownloadRedirectHandler AnyRedirectHandler AnyRedirectHandler AnyRedirectHandler->ImageDownloadRedirectHandler

Types Conforming to Image​Download​Redirect​Handler

AnyRedirectHandler

A wrapper for creating an ImageDownloadRedirectHandler easier. This type conforms to ImageDownloadRedirectHandler and wraps a redirect request modify block.

Requirements

handle​HTTPRedirection(for:​response:​new​Request:​completion​Handler:​)

func handleHTTPRedirection(
        for task: SessionDataTask,
        response: HTTPURLResponse,
        newRequest: URLRequest,
        completionHandler: @escaping (URLRequest?) -> Void) 

The ImageDownloadRedirectHandler contained will be used to change the request before redirection. This is the posibility you can modify the image download request during redirection. You can modify the request for some customizing purpose, such as adding auth token to the header, do basic HTTP auth or something like url mapping.

Usually, you pass an ImageDownloadRedirectHandler as the associated value of KingfisherOptionsInfoItem.redirectHandler and use it as the options parameter in related methods.

If you do nothing with the input request and return it as is, a downloading process will redirect with it.

Parameters

task Session​Data​Task

The current SessionDataTask which triggers this redirect.

response HTTPURLResponse

The response received during redirection.

new​Request URLRequest

The request for redirection which can be modified.

completion​Handler @escaping (URLRequest?) -> Void

A closure for being called with modified request.