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
Showing
3 changed files
with
20 additions
and
13 deletions
| @@ -484,13 +484,6 @@ static NSLock *sessionCookiesLock = nil; | @@ -484,13 +484,6 @@ static NSLock *sessionCookiesLock = nil; | ||
| 484 | for (header in headers) { | 484 | for (header in headers) { |
| 485 | CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[[self requestHeaders] objectForKey:header]); | 485 | CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[[self requestHeaders] objectForKey:header]); |
| 486 | } | 486 | } |
| 487 | - | ||
| 488 | - // If this is a post/put request and we store the request body in memory, add it to the request | ||
| 489 | - if ([self shouldCompressRequestBody] && [self compressedPostBody]) { | ||
| 490 | - CFHTTPMessageSetBody(request, (CFDataRef)[self compressedPostBody]); | ||
| 491 | - } else if ([self postBody]) { | ||
| 492 | - CFHTTPMessageSetBody(request, (CFDataRef)[self postBody]); | ||
| 493 | - } | ||
| 494 | 487 | ||
| 495 | [self loadRequest]; | 488 | [self loadRequest]; |
| 496 | 489 | ||
| @@ -538,9 +531,15 @@ static NSLock *sessionCookiesLock = nil; | @@ -538,9 +531,15 @@ static NSLock *sessionCookiesLock = nil; | ||
| 538 | } | 531 | } |
| 539 | readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream]); | 532 | readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream]); |
| 540 | } else { | 533 | } else { |
| 534 | + | ||
| 541 | // 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 | 535 | // 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 |
| 542 | if ([self postBody]) { | 536 | if ([self postBody]) { |
| 543 | - [self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self postBody]]]; | 537 | + if ([self shouldCompressRequestBody] && [self compressedPostBody]) { |
| 538 | + [self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self compressedPostBody]]]; | ||
| 539 | + } else if ([self postBody]) { | ||
| 540 | + [self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self postBody]]]; | ||
| 541 | + } | ||
| 542 | + [self setPostBodyReadStream:[ASIInputStream inputStreamWithData:[self compressedPostBody]]]; | ||
| 544 | readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream]); | 543 | readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,(CFReadStreamRef)[self postBodyReadStream]); |
| 545 | 544 | ||
| 546 | } else { | 545 | } else { |
| @@ -762,7 +762,7 @@ | @@ -762,7 +762,7 @@ | ||
| 762 | 762 | ||
| 763 | // Test compressed body | 763 | // Test compressed body |
| 764 | // Body is deflated by ASIHTTPRequest, sent, inflated by the server, printed, deflated by mod_deflate, response is inflated by ASIHTTPRequest | 764 | // Body is deflated by ASIHTTPRequest, sent, inflated by the server, printed, deflated by mod_deflate, response is inflated by ASIHTTPRequest |
| 765 | - ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/compressed_post_body"]]; | 765 | + ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/compressed_post_body"]]; |
| 766 | [request setRequestMethod:@"PUT"]; | 766 | [request setRequestMethod:@"PUT"]; |
| 767 | [request setShouldCompressRequestBody:YES]; | 767 | [request setShouldCompressRequestBody:YES]; |
| 768 | [request appendPostData:data]; | 768 | [request appendPostData:data]; |
| @@ -772,7 +772,7 @@ | @@ -772,7 +772,7 @@ | ||
| 772 | success = [[request responseString] isEqualToString:content]; | 772 | success = [[request responseString] isEqualToString:content]; |
| 773 | GHAssertTrue(success,@"Failed to compress the body, or server failed to decompress it"); | 773 | GHAssertTrue(success,@"Failed to compress the body, or server failed to decompress it"); |
| 774 | 774 | ||
| 775 | - request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/compressed_post_body"]]; | 775 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/compressed_post_body"]]; |
| 776 | [request setRequestMethod:@"PUT"]; | 776 | [request setRequestMethod:@"PUT"]; |
| 777 | [request setShouldCompressRequestBody:YES]; | 777 | [request setShouldCompressRequestBody:YES]; |
| 778 | [request setShouldStreamPostDataFromDisk:YES]; | 778 | [request setShouldStreamPostDataFromDisk:YES]; |
| @@ -296,6 +296,7 @@ IMPORTANT | @@ -296,6 +296,7 @@ IMPORTANT | ||
| 296 | NSURL *url; | 296 | NSURL *url; |
| 297 | url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"] autorelease]; | 297 | url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/basic-authentication"] autorelease]; |
| 298 | ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 298 | ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 299 | + [request setUserInfo:[NSDictionary dictionaryWithObject:@"Don't bother" forKey:@"Shall I return any credentials?"]]; | ||
| 299 | [networkQueue addOperation:request]; | 300 | [networkQueue addOperation:request]; |
| 300 | 301 | ||
| 301 | [networkQueue go]; | 302 | [networkQueue go]; |
| @@ -317,6 +318,7 @@ IMPORTANT | @@ -317,6 +318,7 @@ IMPORTANT | ||
| 317 | [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)]; | 318 | [networkQueue setQueueDidFinishSelector:@selector(queueFinished:)]; |
| 318 | 319 | ||
| 319 | request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 320 | request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 321 | + [request setUserInfo:[NSDictionary dictionaryWithObject:@"Don't bother" forKey:@"Shall I return any credentials?"]]; | ||
| 320 | [request setUsername:@"secret_username"]; | 322 | [request setUsername:@"secret_username"]; |
| 321 | [request setPassword:@"secret_password"]; | 323 | [request setPassword:@"secret_password"]; |
| 322 | [networkQueue addOperation:request]; | 324 | [networkQueue addOperation:request]; |
| @@ -355,9 +357,15 @@ IMPORTANT | @@ -355,9 +357,15 @@ IMPORTANT | ||
| 355 | 357 | ||
| 356 | - (void)authorizationNeededForRequest:(ASIHTTPRequest *)request | 358 | - (void)authorizationNeededForRequest:(ASIHTTPRequest *)request |
| 357 | { | 359 | { |
| 358 | - [request setUsername:@"secret_username"]; | 360 | + // We're using this method in multiple tests: |
| 359 | - [request setPassword:@"secret_password"]; | 361 | + // testProgressWithAuthentication will set a userInfo dictionary on the main request, to tell us not to supply credentials |
| 360 | - [request retryWithAuthentication]; | 362 | + if (![request mainRequest] || ![[request mainRequest] userInfo]) { |
| 363 | + [request setUsername:@"secret_username"]; | ||
| 364 | + [request setPassword:@"secret_password"]; | ||
| 365 | + [request retryWithAuthentication]; | ||
| 366 | + } else { | ||
| 367 | + [request cancel]; | ||
| 368 | + } | ||
| 361 | } | 369 | } |
| 362 | 370 | ||
| 363 | 371 |
-
Please register or login to post a comment