Permalink
Browse files

[Issue #505] Handling missing content type correctly

  • Loading branch information...
1 parent c5ac49e commit c0d7e11449b1f2c392f5aba656ab0706c0c15487 @mattt mattt committed Sep 7, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 AFNetworking/AFHTTPRequestOperation.m
@@ -186,7 +186,15 @@ - (BOOL)hasAcceptableContentType {
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 {

0 comments on commit c0d7e11

Please sign in to comment.