Kingfisher: Additional headers in requests

Created on 5 Apr 2016  路  10Comments  路  Source: onevcat/Kingfisher

Hi there,

I'd like to pass some additional headers to my image requests, how can I manage this ?

thx!

Most helpful comment

Since the image setting methods will use the default downloader, you could just set the modifier block to the default downloader to make things easier:

ImageDownloader.defaultDownloader.requestModifier = {
    request in
    // Set request header here
}

All 10 comments

http://cocoadocs.org/docsets/Kingfisher/2.2.0/Classes/ImageDownloader.html#/s:vC10Kingfisher15ImageDownloader15requestModifierGSqFCSo19NSMutableURLRequestT__

Thx @onevcat ! :+1:

@arn00s Could you explain how you sorted it out?

@camill-a I can't find back the code, I finally used Alamofire and Alamofire-Image !

It's find I sorted it out, but Xcode is updating. I'll post my code asap

myImageView.kf_setImageWithURL(URL, optionsInfo:[...]).downloadTask?.ownerDownloader?.requestModifier = { request in
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
    ...
}

It's not working yet, but I guess it's setted before the call as precised in the documentation right?

Since the image setting methods will use the default downloader, you could just set the modifier block to the default downloader to make things easier:

ImageDownloader.defaultDownloader.requestModifier = {
    request in
    // Set request header here
}

Looks better indeed, but where does this instance of ImageDownloader come from?

Edit: I guess it's related to KingfisherManager.sharedManager...
Edit2: Ok my bad, KingFisher import was missing. Shame on me. Thanks a lot

:) Never mind~

Very useful, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joebenton picture joebenton  路  4Comments

HuseyinVural picture HuseyinVural  路  4Comments

kbpontius picture kbpontius  路  3Comments

Tarpsvo picture Tarpsvo  路  5Comments

wudijimao picture wudijimao  路  3Comments