Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Introduce RKStatusCodesOfResponsesWithOptionalBodies #1686

Merged
merged 1 commit into from

2 participants

@segiddins
Owner

Closes #1685

@blakewatters blakewatters was assigned
@segiddins
Owner

@blakewatters lets get this merged in?

@blakewatters
@segiddins segiddins merged commit 770f32a into development

1 check failed

Details default The Travis CI build could not complete due to an error
@segiddins segiddins deleted the bugfix/no-content-type branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 26, 2013
  1. @segiddins
This page is out of date. Refresh to see the latest.
View
3  Code/Network/RKHTTPRequestOperation.m
@@ -35,8 +35,7 @@
static BOOL RKResponseRequiresContentTypeMatch(NSHTTPURLResponse *response, NSURLRequest *request)
{
if (RKRequestMethodFromString(request.HTTPMethod) == RKRequestMethodHEAD) return NO;
- if (response.statusCode == 304) return NO;
- if (response.statusCode == 204) return NO;
+ if ([RKStatusCodesOfResponsesWithOptionalBodies() containsIndex:response.statusCode]) return NO;
return YES;
}
View
7 Code/ObjectMapping/RKHTTPUtilities.h
@@ -143,3 +143,10 @@ BOOL RKURLIsRelativeToURL(NSURL *URL, NSURL *baseURL);
@return A string containing the relative path and query parameters.
*/
NSString *RKPathAndQueryStringFromURLRelativeToURL(NSURL *URL, NSURL *baseURL);
+
+/**
+ * Returns an index set of the status codes with optional response bodies
+ *
+ * @return An index set of the status codes with optional response bodies
+ */
+NSIndexSet *RKStatusCodesOfResponsesWithOptionalBodies(void);
View
11 Code/ObjectMapping/RKHTTPUtilities.m
@@ -535,3 +535,14 @@ BOOL RKURLIsRelativeToURL(NSURL *URL, NSURL *baseURL)
return (query && [query length]) ? [NSString stringWithFormat:@"%@?%@", pathWithPrevervedTrailingSlash, query] : pathWithPrevervedTrailingSlash;
}
}
+
+NSIndexSet *RKStatusCodesOfResponsesWithOptionalBodies()
+{
+ NSMutableIndexSet *statusCodes = [NSMutableIndexSet indexSet];
+ [statusCodes addIndex:201];
+ [statusCodes addIndex:202];
+ [statusCodes addIndex:204];
+ [statusCodes addIndex:205];
+ [statusCodes addIndex:304];
+ return statusCodes;
+}
View
12 Tests/Logic/Network/RKHTTPRequestOperationTest.m
@@ -78,4 +78,16 @@ - (void)testThatLoadingA204StatusDoesNotReturnExpectedContentTypeErrorWithMissin
expect(requestOperation.error).to.beNil();
}
+- (void)testThatLoadingA202StatusDoesNotReturnExpectedContentTypeErrorWithMissingContentType
+{
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"/no_content_type/202" relativeToURL:[RKTestFactory baseURL]]];
+ RKHTTPRequestOperation *requestOperation = [[RKHTTPRequestOperation alloc] initWithRequest:request];
+ requestOperation.acceptableContentTypes = [NSSet setWithObject:@"text/xml"];
+ requestOperation.acceptableStatusCodes = [NSIndexSet indexSetWithIndex:202];
+ [requestOperation start];
+ [requestOperation waitUntilFinished];
+
+ expect(requestOperation.error).to.beNil();
+}
+
@end
Something went wrong with that request. Please try again.