Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce RKStatusCodesOfResponsesWithOptionalBodies #1686

Merged
merged 1 commit into from
Dec 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Code/Network/RKHTTPRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions Code/ObjectMapping/RKHTTPUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
11 changes: 11 additions & 0 deletions Code/ObjectMapping/RKHTTPUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions Tests/Logic/Network/RKHTTPRequestOperationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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