New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add header to image request #51
Comments
Already supported and mentioned on Readme:
See the wiki, you need to pass the context option Wiki : https://github.com/SDWebImage/SDWebImage/wiki/How-to-use#use-request-modifier-50 I don't want to add many code sample or details in readme, since it's for beginner and quick guide for a framework. For details, the docuementation and wikis is always the better place to check. |
You can also just use another API, but this will apply to all image requests, and does not support a block-based arg (Which means, it's static, not dynamic). But it's simpler: |
The wiki exemple worked perfectly! Thank you! |
@vipatronon I update the readme with a new chapter called Customization and configuration setup, make it easier for new user to find the place to do something setup about HTTP headers, coder plugins. Hope this can help for you. https://github.com/SDWebImage/SDWebImageSwiftUI#customization-and-configuration-setup |
@dreampiggy thank you for updating the readme, I helped me for sure and I think this will help new users too |
@dreampiggy I still don't get it. How can you add a header for a single request? Where / how do you passt the requestModifier for a single request? |
When using
You know how to use... Though this API not really convenient for simple use case. You can wrap it into a category for convenient |
let requestModifier = SDWebImageDownloaderRequestModifier { (request) -> URLRequest? in
if (request.url?.host == "foo") {
var mutableRequest = request
mutableRequest.setValue("foo=bar", forHTTPHeaderField: "Cookie")
return mutableRequest
}
return request
};
imageView.sd_setImage(with: url, options: [], context: [.requestModifier] = requestModifier]) { } |
Thank you so much, this clears it up a lot for me! :) |
There may be a chance for SD to provide better convenient for common Swift users. And this repo can be merged into SDWebImage Core repo (current Objective-C only) I've have a plan and demo in SDWebImage/swift fork branch to make SDWebImage 6.0 become Swift-Objc-mixed and provide massive better support like enum-associated-object/concurrency/result type, etc). imageView.sd.setImage(with: url, options: [.header(["Foo": "Bar"])]) {
switch $0 {
case .success(let result):
print(result.image.size)
print(result.cacheType)
case .failure(let error):
if case let .badImageData(data, url) = error {
print("\(url) is not image url")
} else {
print(error)
}
}
}
// or
do {
let result = try await manager.loadImage(with: url)
} catch e {
// ...
} But seems has no extra time to make it finished recently... Need someone from community to help |
Is there a way to add a header value to the WebImage component? To get the images from my server, I must pass some info in there
Thanks in advance
The text was updated successfully, but these errors were encountered: