Skip to content

Loading…

AFImageRequestOperation tweaks #896

Closed
wants to merge 3 commits into from

2 participants

@jam
jam commented

This pull request fixes a couple of issues I was having when using AFImageRequestOperation.

  • One of the servers my app tried to connect to was returning JPEG images with a content type of image/jpg. While technically incorrect, this caused the operation to fail, which isn't desirable behaviour. Unfortunately the server isn't one I control, otherwise I'd have made the change on the server side.

  • While attempting to subclass AFImageRequestOperation to include the invalid type, I noticed that imageRequestOperationWithRequest:imageProcessingBlock:success:failure: always returned AFImageRequestOperation instances, rather than instances of the current class (like the other request operation classes).

jam added some commits
@jam jam Use "self" when creating an AFImageRequestOperation object using the …
…convenience class method.

This enables using the method with subclasses.
c65b29f
@jam jam Accept "image/jpg" as a valid content type for AFImageRequestOperation.
This is technically incorrect, as "image/jpg" is not a valid MIME type, but certain web servers return this type for JPEG images which causes AFImageRequestOperation to fail.
cf28d1b
@jam jam Use "self" when creating AFImageRequestOperation objects using the cl…
…ass method on OS X too.
07537b1
@mattt

Thanks for submitting this pull request, @jam.

You're absolutely correct to fix the use of an explicit class instead of self in the class methods. Every other subclass in AFNetworking core does this except AFImageRequestOperation, until ab00b95. I credited you for the patch, which combines the two you had, and adds a cast, for consistency.

As for adding the acceptable content type, there is a class method for just that purpose (which means that you didn't have to subclass to begin with): AFHTTPRequestOperation +addAcceptableContentTypes:.

@mattt mattt closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2013
  1. @jam

    Use "self" when creating an AFImageRequestOperation object using the …

    jam committed
    …convenience class method.
    
    This enables using the method with subclasses.
  2. @jam

    Accept "image/jpg" as a valid content type for AFImageRequestOperation.

    jam committed
    This is technically incorrect, as "image/jpg" is not a valid MIME type, but certain web servers return this type for JPEG images which causes AFImageRequestOperation to fail.
  3. @jam

    Use "self" when creating AFImageRequestOperation objects using the cl…

    jam committed
    …ass method on OS X too.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 AFNetworking/AFImageRequestOperation.m
View
6 AFNetworking/AFImageRequestOperation.m
@@ -75,7 +75,7 @@ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
- AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
+ AFImageRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
UIImage *image = responseObject;
@@ -106,7 +106,7 @@ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
- AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
+ AFImageRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
NSImage *image = responseObject;
@@ -185,7 +185,7 @@ - (NSImage *)responseImage {
#pragma mark - AFHTTPRequestOperation
+ (NSSet *)acceptableContentTypes {
- return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];
+ return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/jpg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];
}
+ (BOOL)canProcessRequest:(NSURLRequest *)request {
Something went wrong with that request. Please try again.