From c0d7e11449b1f2c392f5aba656ab0706c0c15487 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 7 Sep 2012 16:45:12 -0700 Subject: [PATCH] [Issue #505] Handling missing content type correctly --- AFNetworking/AFHTTPRequestOperation.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 9d09e1c..1456eca 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -186,7 +186,15 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { return NO; } - return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:[self.response MIMEType]]; + // According to RFC 2616: + // Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream". + // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html + NSString *contentType = [self.response MIMEType]; + if (!contentType) { + contentType = @"application/octet-stream"; + } + + return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:contentType]; } - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue {