Ben Copsey

Fix compressed post bodies that aren't streamed from disk

Remove old calls to set the post body on the request - these aren't needed anymore
Fix progressWithAuthentication test so the delegate doesn't supply credentials
... ... @@ -484,13 +484,6 @@ static NSLock *sessionCookiesLock = nil;
for (header in headers) {
CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[[self requestHeaders] objectForKey:header]);
}
// If this is a post/put request and we store the request body in memory, add it to the request
if ([self shouldCompressRequestBody] && [self compressedPostBody]) {
CFHTTPMessageSetBody(request, (CFDataRef)[self compressedPostBody]);
} else if ([self postBody]) {
CFHTTPMessageSetBody(request, (CFDataRef)[self postBody]);
}
[self loadRequest];
... ... @@ -538,9 +531,15 @@ static NSLock *sessionCookiesLock = nil;
}
readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream]);
} else {
// If we have a request body, we'll stream it from memory using our custom stream, so that we can measure bandwidth use and it can be bandwidth-throttled if nescessary
if ([self postBody]) {
[self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self postBody]]];
if ([self shouldCompressRequestBody] && [self compressedPostBody]) {
[self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self compressedPostBody]]];
} else if ([self postBody]) {
[self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self postBody]]];
}
[self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self compressedPostBody]]];
readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream]);
} else {
... ...
... ... @@ -762,7 +762,7 @@
// Test compressed body
// Body is deflated by ASIHTTPRequest, sent, inflated by the server, printed, deflated by mod_deflate, response is inflated by ASIHTTPRequest
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/compressed_post_body"]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/compressed_post_body"]];
[request setRequestMethod:@"PUT"];
[request setShouldCompressRequestBody:YES];
[request appendPostData:data];
... ... @@ -772,7 +772,7 @@
success = [[request responseString] isEqualToString:content];
GHAssertTrue(success,@"Failed to compress the body, or server failed to decompress it");
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/compressed_post_body"]];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/compressed_post_body"]];
[request setRequestMethod:@"PUT"];
[request setShouldCompressRequestBody:YES];
[request setShouldStreamPostDataFromDisk:YES];
... ...
... ... @@ -296,6 +296,7 @@ IMPORTANT
NSURL *url;
url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"] autorelease];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"Don't bother" forKey:@"Shall I return any credentials?"]];
[networkQueue addOperation:request];
[networkQueue go];
... ... @@ -317,6 +318,7 @@ IMPORTANT
[networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"Don't bother" forKey:@"Shall I return any credentials?"]];
[request setUsername:@"secret_username"];
[request setPassword:@"secret_password"];
[networkQueue addOperation:request];
... ... @@ -355,9 +357,15 @@ IMPORTANT
- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
{
[request setUsername:@"secret_username"];
[request setPassword:@"secret_password"];
[request retryWithAuthentication];
// We're using this method in multiple tests:
// testProgressWithAuthentication will set a userInfo dictionary on the main request, to tell us not to supply credentials
if (![request mainRequest] || ![[request mainRequest] userInfo]) {
[request setUsername:@"secret_username"];
[request setPassword:@"secret_password"];
[request retryWithAuthentication];
} else {
[request cancel];
}
}
... ...