Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Introduce RKStatusCodesOfResponsesWithOptionalBodies #1686

Merged
merged 1 commit into from

2 participants

Samuel E. Giddins Blake Watters
Samuel E. Giddins
Owner

Closes #1685

Blake Watters blakewatters was assigned
Samuel E. Giddins
Owner

@blakewatters lets get this merged in?

Blake Watters
Samuel E. Giddins segiddins merged commit 770f32a into from
Samuel E. Giddins segiddins deleted the 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. Samuel E. Giddins
This page is out of date. Refresh to see the latest.
3  Code/Network/RKHTTPRequestOperation.m
View
@@ -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;
}
7 Code/ObjectMapping/RKHTTPUtilities.h
View
@@ -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 Code/ObjectMapping/RKHTTPUtilities.m
View
@@ -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 Tests/Logic/Network/RKHTTPRequestOperationTest.m
View
@@ -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.