Alamofire / AlamofireImage

AlamofireImage is an image component library for Alamofire
MIT License
3.99k stars 523 forks source link

Expose acceptableImageContentTypes #453

Closed lickel closed 1 year ago

lickel commented 2 years ago

Goals :soccer:

Expose ImageResponseSerializer.acceptableImageContentTypes for read-only consumption by API consumers.

Implementation Details :construction:

I have had a few instances where I need to express valid content types. The most recent use case was within a SwiftUI view where I wanted to download an image directly.

Testing Details :mag:

n/a

jshier commented 2 years ago

Simple enough, but can you clarify why you would ever need to access this value directly? If you need to download an image, I'd suggest wrapping an ImageDownloader into a SwiftUI view so you can take advantage of all of the AlamofireImage features.

lickel commented 2 years ago

I am using ImageDownloader. My issue is I want the same URLRequest that I would get from UIImageView.setImage(withURL...)

Those conversions are all in private extension functions with the form:

    private func urlRequest(with url: URL) -> URLRequest {
        var urlRequest = URLRequest(url: url)

        for mimeType in ImageResponseSerializer.acceptableImageContentTypes.sorted() {
            urlRequest.addValue(mimeType, forHTTPHeaderField: "Accept")
        }

        return urlRequest
    }
lickel commented 2 years ago

The other alternative would be to expose that func urlRequest(with url: URL) behavior publicly, e.g on ImageDownloader

jshier commented 2 years ago

Makes sense. This is probably an okay change, but I'll think about it more.

lickel commented 2 years ago

@jshier have you had a chance to give this more thought?

jshier commented 2 years ago

Makes sense, I just need to do some other updates before I can test and merge.

lickel commented 2 years ago

Just following up; do you think you'd be willing to merge this in?