Added in "image/jpg" acceptable content type for Image Requests #199
Added in "image/jpg" acceptable content type for Image Requests #199
Conversation
I ran into an API that was returning images as "image/jpg", which I noticed was not included as a default content type for the image request. This change fixes that.
Bah, that's not the right Mime type at all :( This actually brings up a weakness in the framework that I've come across on a few recent occasions—the amount of effort needed to workaround the built-in strictness to content-types. There was someone on Stack Overflow recently that had an API returning JSON as an incorrect mime type, and I was frustrated by how complicated the answer my answer was for that. And it's not just incorrect mime types—Amazon and GitHub, for example, serve specifally-vendor-prefix-types, which would result in an error with AFNetworking. Expanding the acceptable content types is a good band-aid, but it's not a great long-term solution, I'm afraid... Do you (or does anyone else) have any strong opinions on the matter? Any ideas on how this should be addressed, if at all? |
That's a great point. I didn't even double check to see if that was valid Mime type - just assumed it. It's API in development right now for a client, so I'll actually just get them to change it on their end. However, it does present a problem since I was using the UIImageView category to load images for a TableView, and as far as I know the only way I could fix this issue here is by changing AFImageRequestOperation directly and adding it there. (which I prefer to not do). |
What do you think about using class methods to define acceptable content types and path extensions? e.g.: [AFImageRequestOperation setAcceptableContentTypes:[NSSet setWithObjects:@"image/jpg", ...]]; I worry about the possibility of declarations overriding each other like this, so maybe only support adding of acceptableContentTypes? [AFImageRequestOperation addAcceptableContentType:@"image/jpg"]; |
I think I like the second approach better than the first. I'm having a hardtime why people wouldn't want the default set. |
+1 for the second option, as long as I can pass an array of types in rather than one by one ;) |
To piggy back on my comment in #228, this issue might just be related to However, there is no patch through to the I may take some time this weekend and play around with this idea. |
@kcharwood Yeah, I'm actually quite happy with the approach described in #228. Thanks again for your thoughts on this—I'm excited to have this in the next release of AFNetworking. |
I ran into an API that was returning images as "image/jpg", which I
noticed was not included as a default content type for the image
request. This change fixes that.