Skip to content

Commit

Permalink
Added test for properly setting the Content-Length header for RKParam…
Browse files Browse the repository at this point in the history
…s file uploads. Test appears to pass, contradicting concerns raised in RestKit#420.
  • Loading branch information
Jeff Arena committed Jan 20, 2012
1 parent b1f4e1f commit 3b6c0a2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Specs/Network/RKParamsSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ - (void)testShouldCalculateAnMD5ForTheParams {
assertThat(MD5, is(equalTo(@"da7d80084b86aa5022b434e3bf084caf")));
}

- (void)testShouldProperlyCalculateContentLengthForFileUploads {
RKClient* client = RKSpecNewClient();
RKParams* params = [RKParams params];
[params setValue:@"one" forParam:@"value"];
[params setValue:@"two" forParam:@"value"];
[params setValue:@"three" forParam:@"value"];
[params setValue:@"four" forParam:@"value"];
NSBundle *testBundle = [NSBundle bundleWithIdentifier:@"org.restkit.unit-tests"];
NSString *imagePath = [testBundle pathForResource:@"blake" ofType:@"png"];
NSData *data = [NSData dataWithContentsOfFile:imagePath];
[params setData:data MIMEType:@"image/png" forParam:@"file"];
RKRequest *request = [client requestWithResourcePath:@"/upload"];
[request setMethod:RKRequestMethodPOST];
request.params = params;
[request prepareURLRequest];
assertThatInteger([params HTTPHeaderValueForContentLength], is(equalToInt(23166)));
assertThat([[request.URLRequest allHTTPHeaderFields] objectForKey:@"Content-Length"], is(equalTo(@"23166")));
}

@end

0 comments on commit 3b6c0a2

Please sign in to comment.