Ben Copsey

Start work on new concurrent ASIHTTPRequest :)

@@ -312,6 +312,8 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -312,6 +312,8 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
312 // This only affects credentials stored in the session cache when useSessionPersistance is YES. Credentials from the keychain are never presented unless the server asks for them 312 // This only affects credentials stored in the session cache when useSessionPersistance is YES. Credentials from the keychain are never presented unless the server asks for them
313 // Default is YES 313 // Default is YES
314 BOOL shouldPresentCredentialsBeforeChallenge; 314 BOOL shouldPresentCredentialsBeforeChallenge;
  315 +
  316 + BOOL isSynchronous;
315 } 317 }
316 318
317 #pragma mark init / dealloc 319 #pragma mark init / dealloc
@@ -353,14 +355,17 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -353,14 +355,17 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
353 355
354 #pragma mark running a request 356 #pragma mark running a request
355 357
356 -// Run a request asynchronously by adding it to the global queue 358 +// For an asynchronous request in the current thread, use [request start]
357 -// (Use [request start] for a synchronous request) 359 +
358 -- (void)startAsynchronous; 360 +// Run a request asynchronously in the background by adding it to the global queue, where it will run in its own thread
  361 +- (void)startInBackgroundThread;
  362 +
  363 +// Run a request synchronously in the current thread
  364 +- (void)startSynchronous;
359 365
360 -#pragma mark request logic  
361 366
362 -// Main request loop is in here 367 +
363 -- (void)loadRequest; 368 +#pragma mark request logic
364 369
365 // Start the read stream. Called by loadRequest, and again to restart the request when authentication is needed 370 // Start the read stream. Called by loadRequest, and again to restart the request when authentication is needed
366 - (void)startRequest; 371 - (void)startRequest;
@@ -639,4 +644,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -639,4 +644,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
639 @property (assign, readonly) int proxyAuthenticationRetryCount; 644 @property (assign, readonly) int proxyAuthenticationRetryCount;
640 @property (assign) BOOL haveBuiltRequestHeaders; 645 @property (assign) BOOL haveBuiltRequestHeaders;
641 @property (assign, nonatomic) BOOL haveBuiltPostBody; 646 @property (assign, nonatomic) BOOL haveBuiltPostBody;
  647 +
  648 +@property (assign, readonly) BOOL isSynchronous;
  649 +
642 @end 650 @end
This diff is collapsed. Click to expand it.
@@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
39 [request setPostValue:d forKey:@"post_var2"]; 39 [request setPostValue:d forKey:@"post_var2"];
40 [request setPostValue:v forKey:@"post_var3"]; 40 [request setPostValue:v forKey:@"post_var3"];
41 [request setFile:path forKey:@"file"]; 41 [request setFile:path forKey:@"file"];
42 - [request start]; 42 + [request startSynchronous];
43 43
44 BOOL success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"bigfile",size,@"application/octet-stream"]]); 44 BOOL success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"bigfile",size,@"application/octet-stream"]]);
45 GHAssertTrue(success,@"Failed to upload the correct data (using local file)"); 45 GHAssertTrue(success,@"Failed to upload the correct data (using local file)");
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 [request setPostValue:d forKey:@"post_var2"]; 50 [request setPostValue:d forKey:@"post_var2"];
51 [request setPostValue:v forKey:@"post_var3"]; 51 [request setPostValue:v forKey:@"post_var3"];
52 [request setData:data forKey:@"file"]; 52 [request setData:data forKey:@"file"];
53 - [request start]; 53 + [request startSynchronous];
54 54
55 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"file",size,@"application/octet-stream"]]); 55 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"file",size,@"application/octet-stream"]]);
56 GHAssertTrue(success,@"Failed to upload the correct data (using NSData)"); 56 GHAssertTrue(success,@"Failed to upload the correct data (using NSData)");
@@ -61,7 +61,7 @@ @@ -61,7 +61,7 @@
61 [request setPostValue:d forKey:@"post_var2"]; 61 [request setPostValue:d forKey:@"post_var2"];
62 [request setPostValue:v forKey:@"post_var3"]; 62 [request setPostValue:v forKey:@"post_var3"];
63 [request setFile:path withFileName:@"myfile" andContentType:@"text/plain" forKey:@"file"]; 63 [request setFile:path withFileName:@"myfile" andContentType:@"text/plain" forKey:@"file"];
64 - [request start]; 64 + [request startSynchronous];
65 65
66 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"myfile",size,@"text/plain"]]); 66 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"myfile",size,@"text/plain"]]);
67 GHAssertTrue(success,@"Failed to send the correct content-type / file name"); 67 GHAssertTrue(success,@"Failed to send the correct content-type / file name");
@@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
72 [request setPostValue:d forKey:@"post_var2"]; 72 [request setPostValue:d forKey:@"post_var2"];
73 [request setPostValue:v forKey:@"post_var3"]; 73 [request setPostValue:v forKey:@"post_var3"];
74 [request setData:data withFileName:@"myfile" andContentType:@"text/plain" forKey:@"file"]; 74 [request setData:data withFileName:@"myfile" andContentType:@"text/plain" forKey:@"file"];
75 - [request start]; 75 + [request startSynchronous];
76 76
77 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"myfile",size,@"text/plain"]]); 77 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu\r\ncontent_type: %@",@"foo",d,v,@"myfile",size,@"text/plain"]]);
78 GHAssertTrue(success,@"Failed to send the correct content-type / file name"); 78 GHAssertTrue(success,@"Failed to send the correct content-type / file name");
@@ -88,7 +88,7 @@ @@ -88,7 +88,7 @@
88 [request setPostValue:@"there" forKey:@"xxx_non_empty_string"]; 88 [request setPostValue:@"there" forKey:@"xxx_non_empty_string"];
89 [request setShouldStreamPostDataFromDisk:YES]; 89 [request setShouldStreamPostDataFromDisk:YES];
90 [request buildPostBody]; 90 [request buildPostBody];
91 - [request start]; 91 + [request startSynchronous];
92 92
93 BOOL success = ([[request responseString] isEqualToString:@"a_non_empty_string: hello\r\nzzz_empty_string: \r\nxxx_non_empty_string: there"]); 93 BOOL success = ([[request responseString] isEqualToString:@"a_non_empty_string: hello\r\nzzz_empty_string: \r\nxxx_non_empty_string: there"]);
94 GHAssertTrue(success,@"Failed to send the correct post data"); 94 GHAssertTrue(success,@"Failed to send the correct post data");
@@ -114,7 +114,7 @@ @@ -114,7 +114,7 @@
114 114
115 [request setShouldStreamPostDataFromDisk:YES]; 115 [request setShouldStreamPostDataFromDisk:YES];
116 [request setPostFormat:ASIURLEncodedPostFormat]; 116 [request setPostFormat:ASIURLEncodedPostFormat];
117 - [request start]; 117 + [request startSynchronous];
118 118
119 119
120 BOOL success = ([[request responseString] isEqualToString:@"value1: value1\r\nvalue2: (%20 ? =)\r\nvalue3: £100.00\r\nvalue4: \r\nteskey&aa: &??aaa=//ciaoèèè"]); 120 BOOL success = ([[request responseString] isEqualToString:@"value1: value1\r\nvalue2: (%20 ? =)\r\nvalue3: £100.00\r\nvalue4: \r\nteskey&aa: &??aaa=//ciaoèèè"]);
@@ -130,7 +130,7 @@ @@ -130,7 +130,7 @@
130 NSString *charset = @"utf-8"; 130 NSString *charset = @"utf-8";
131 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 131 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
132 [request setPostValue:testString forKey:@"value"]; 132 [request setPostValue:testString forKey:@"value"];
133 - [request start]; 133 + [request startSynchronous];
134 BOOL success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); 134 BOOL success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]);
135 GHAssertTrue(success,@"Failed to correctly encode the data"); 135 GHAssertTrue(success,@"Failed to correctly encode the data");
136 136
@@ -138,7 +138,7 @@ @@ -138,7 +138,7 @@
138 request = [ASIFormDataRequest requestWithURL:url]; 138 request = [ASIFormDataRequest requestWithURL:url];
139 [request setPostValue:testString forKey:@"value"]; 139 [request setPostValue:testString forKey:@"value"];
140 [request setPostFormat:ASIMultipartFormDataPostFormat]; 140 [request setPostFormat:ASIMultipartFormDataPostFormat];
141 - [request start]; 141 + [request startSynchronous];
142 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); 142 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]);
143 GHAssertTrue(success,@"Failed to correctly encode the data"); 143 GHAssertTrue(success,@"Failed to correctly encode the data");
144 144
@@ -148,7 +148,7 @@ @@ -148,7 +148,7 @@
148 request = [ASIFormDataRequest requestWithURL:url]; 148 request = [ASIFormDataRequest requestWithURL:url];
149 [request setPostValue:testString forKey:@"value"]; 149 [request setPostValue:testString forKey:@"value"];
150 [request setStringEncoding:NSISOLatin1StringEncoding]; 150 [request setStringEncoding:NSISOLatin1StringEncoding];
151 - [request start]; 151 + [request startSynchronous];
152 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); 152 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]);
153 GHAssertTrue(success,@"Failed to correctly encode the data"); 153 GHAssertTrue(success,@"Failed to correctly encode the data");
154 154
@@ -157,7 +157,7 @@ @@ -157,7 +157,7 @@
157 [request setPostValue:testString forKey:@"value"]; 157 [request setPostValue:testString forKey:@"value"];
158 [request setPostFormat:ASIMultipartFormDataPostFormat]; 158 [request setPostFormat:ASIMultipartFormDataPostFormat];
159 [request setStringEncoding:NSISOLatin1StringEncoding]; 159 [request setStringEncoding:NSISOLatin1StringEncoding];
160 - [request start]; 160 + [request startSynchronous];
161 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); 161 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]);
162 GHAssertTrue(success,@"Failed to correctly encode the data"); 162 GHAssertTrue(success,@"Failed to correctly encode the data");
163 163
@@ -166,7 +166,7 @@ @@ -166,7 +166,7 @@
166 request = [ASIFormDataRequest requestWithURL:url]; 166 request = [ASIFormDataRequest requestWithURL:url];
167 [request setPostValue:testString forKey:@"value"]; 167 [request setPostValue:testString forKey:@"value"];
168 [request setStringEncoding:NSWindowsCP1252StringEncoding]; 168 [request setStringEncoding:NSWindowsCP1252StringEncoding];
169 - [request start]; 169 + [request startSynchronous];
170 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); 170 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]);
171 GHAssertTrue(success,@"Failed to correctly encode the data"); 171 GHAssertTrue(success,@"Failed to correctly encode the data");
172 172
@@ -174,7 +174,7 @@ @@ -174,7 +174,7 @@
174 [request setPostValue:testString forKey:@"value"]; 174 [request setPostValue:testString forKey:@"value"];
175 [request setPostFormat:ASIMultipartFormDataPostFormat]; 175 [request setPostFormat:ASIMultipartFormDataPostFormat];
176 [request setStringEncoding:NSWindowsCP1252StringEncoding]; 176 [request setStringEncoding:NSWindowsCP1252StringEncoding];
177 - [request start]; 177 + [request startSynchronous];
178 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]); 178 success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"Got data in %@: %@",charset,testString]]);
179 GHAssertTrue(success,@"Failed to correctly encode the data"); 179 GHAssertTrue(success,@"Failed to correctly encode the data");
180 180
This diff is collapsed. Click to expand it.
@@ -118,7 +118,7 @@ static NSString *bucket = @""; @@ -118,7 +118,7 @@ static NSString *bucket = @"";
118 [request setDateString:dateString]; 118 [request setDateString:dateString];
119 [request setSecretAccessKey:exampleSecretAccessKey]; 119 [request setSecretAccessKey:exampleSecretAccessKey];
120 [request setAccessKey:exampleAccessKey]; 120 [request setAccessKey:exampleAccessKey];
121 - [request start]; 121 + [request startSynchronous];
122 GHAssertNotNil([request error],@"Failed to generate an error when the request was not correctly signed"); 122 GHAssertNotNil([request error],@"Failed to generate an error when the request was not correctly signed");
123 123
124 BOOL success = ([[request error] code] == ASIS3ResponseErrorType); 124 BOOL success = ([[request error] code] == ASIS3ResponseErrorType);
@@ -147,7 +147,7 @@ static NSString *bucket = @""; @@ -147,7 +147,7 @@ static NSString *bucket = @"";
147 ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path]; 147 ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path];
148 [request setSecretAccessKey:secretAccessKey]; 148 [request setSecretAccessKey:secretAccessKey];
149 [request setAccessKey:accessKey]; 149 [request setAccessKey:accessKey];
150 - [request start]; 150 + [request startSynchronous];
151 success = [[request responseString] isEqualToString:@""]; 151 success = [[request responseString] isEqualToString:@""];
152 GHAssertTrue(success,@"Failed to PUT a file to S3"); 152 GHAssertTrue(success,@"Failed to PUT a file to S3");
153 153
@@ -155,7 +155,7 @@ static NSString *bucket = @""; @@ -155,7 +155,7 @@ static NSString *bucket = @"";
155 request = [ASIS3Request requestWithBucket:bucket path:path]; 155 request = [ASIS3Request requestWithBucket:bucket path:path];
156 [request setSecretAccessKey:secretAccessKey]; 156 [request setSecretAccessKey:secretAccessKey];
157 [request setAccessKey:accessKey]; 157 [request setAccessKey:accessKey];
158 - [request start]; 158 + [request startSynchronous];
159 success = [[request responseString] isEqualToString:@"This is my content"]; 159 success = [[request responseString] isEqualToString:@"This is my content"];
160 GHAssertTrue(success,@"Failed to GET the correct data from S3"); 160 GHAssertTrue(success,@"Failed to GET the correct data from S3");
161 161
@@ -163,14 +163,14 @@ static NSString *bucket = @""; @@ -163,14 +163,14 @@ static NSString *bucket = @"";
163 request = [ASIS3Request COPYRequestFromBucket:bucket path:path toBucket:bucket path:@"/test-copy"]; 163 request = [ASIS3Request COPYRequestFromBucket:bucket path:path toBucket:bucket path:@"/test-copy"];
164 [request setSecretAccessKey:secretAccessKey]; 164 [request setSecretAccessKey:secretAccessKey];
165 [request setAccessKey:accessKey]; 165 [request setAccessKey:accessKey];
166 - [request start]; 166 + [request startSynchronous];
167 GHAssertNil([request error],@"Failed to COPY a file"); 167 GHAssertNil([request error],@"Failed to COPY a file");
168 168
169 // GET the copy 169 // GET the copy
170 request = [ASIS3Request requestWithBucket:bucket path:@"/test-copy"]; 170 request = [ASIS3Request requestWithBucket:bucket path:@"/test-copy"];
171 [request setSecretAccessKey:secretAccessKey]; 171 [request setSecretAccessKey:secretAccessKey];
172 [request setAccessKey:accessKey]; 172 [request setAccessKey:accessKey];
173 - [request start]; 173 + [request startSynchronous];
174 success = [[request responseString] isEqualToString:@"This is my content"]; 174 success = [[request responseString] isEqualToString:@"This is my content"];
175 GHAssertTrue(success,@"Failed to GET the correct data from S3"); 175 GHAssertTrue(success,@"Failed to GET the correct data from S3");
176 176
@@ -179,7 +179,7 @@ static NSString *bucket = @""; @@ -179,7 +179,7 @@ static NSString *bucket = @"";
179 request = [ASIS3Request HEADRequestWithBucket:bucket path:@"/test-copy"]; 179 request = [ASIS3Request HEADRequestWithBucket:bucket path:@"/test-copy"];
180 [request setSecretAccessKey:secretAccessKey]; 180 [request setSecretAccessKey:secretAccessKey];
181 [request setAccessKey:accessKey]; 181 [request setAccessKey:accessKey];
182 - [request start]; 182 + [request startSynchronous];
183 success = [[request responseString] isEqualToString:@""]; 183 success = [[request responseString] isEqualToString:@""];
184 GHAssertTrue(success,@"Got a response body for a HEAD request"); 184 GHAssertTrue(success,@"Got a response body for a HEAD request");
185 185
@@ -188,7 +188,7 @@ static NSString *bucket = @""; @@ -188,7 +188,7 @@ static NSString *bucket = @"";
188 [listRequest setPrefix:@"test"]; 188 [listRequest setPrefix:@"test"];
189 [listRequest setSecretAccessKey:secretAccessKey]; 189 [listRequest setSecretAccessKey:secretAccessKey];
190 [listRequest setAccessKey:accessKey]; 190 [listRequest setAccessKey:accessKey];
191 - [listRequest start]; 191 + [listRequest startSynchronous];
192 GHAssertNil([listRequest error],@"Failed to download a list from S3"); 192 GHAssertNil([listRequest error],@"Failed to download a list from S3");
193 success = [[listRequest bucketObjects] count]; 193 success = [[listRequest bucketObjects] count];
194 GHAssertTrue(success,@"The file didn't show up in the list"); 194 GHAssertTrue(success,@"The file didn't show up in the list");
@@ -198,7 +198,7 @@ static NSString *bucket = @""; @@ -198,7 +198,7 @@ static NSString *bucket = @"";
198 [request setSecretAccessKey:secretAccessKey]; 198 [request setSecretAccessKey:secretAccessKey];
199 [request setRequestMethod:@"DELETE"]; 199 [request setRequestMethod:@"DELETE"];
200 [request setAccessKey:accessKey]; 200 [request setAccessKey:accessKey];
201 - [request start]; 201 + [request startSynchronous];
202 success = [[request responseString] isEqualToString:@""]; 202 success = [[request responseString] isEqualToString:@""];
203 GHAssertTrue(success,@"Failed to DELETE the file from S3"); 203 GHAssertTrue(success,@"Failed to DELETE the file from S3");
204 204
@@ -207,7 +207,7 @@ static NSString *bucket = @""; @@ -207,7 +207,7 @@ static NSString *bucket = @"";
207 [request setSecretAccessKey:secretAccessKey]; 207 [request setSecretAccessKey:secretAccessKey];
208 [request setRequestMethod:@"DELETE"]; 208 [request setRequestMethod:@"DELETE"];
209 [request setAccessKey:accessKey]; 209 [request setAccessKey:accessKey];
210 - [request start]; 210 + [request startSynchronous];
211 success = [[request responseString] isEqualToString:@""]; 211 success = [[request responseString] isEqualToString:@""];
212 GHAssertTrue(success,@"Failed to DELETE the copy from S3"); 212 GHAssertTrue(success,@"Failed to DELETE the copy from S3");
213 213
@@ -215,7 +215,7 @@ static NSString *bucket = @""; @@ -215,7 +215,7 @@ static NSString *bucket = @"";
215 request = [ASIS3Request COPYRequestFromBucket:bucket path:path toBucket:bucket path:@"/test-copy"]; 215 request = [ASIS3Request COPYRequestFromBucket:bucket path:path toBucket:bucket path:@"/test-copy"];
216 [request setSecretAccessKey:secretAccessKey]; 216 [request setSecretAccessKey:secretAccessKey];
217 [request setAccessKey:accessKey]; 217 [request setAccessKey:accessKey];
218 - [request start]; 218 + [request startSynchronous];
219 GHAssertNotNil([request error],@"Failed generate an error for what should have been a failed COPY"); 219 GHAssertNotNil([request error],@"Failed generate an error for what should have been a failed COPY");
220 220
221 success = [[[request error] localizedDescription] isEqualToString:@"The specified key does not exist."]; 221 success = [[[request error] localizedDescription] isEqualToString:@"The specified key does not exist."];
@@ -243,7 +243,7 @@ static NSString *bucket = @""; @@ -243,7 +243,7 @@ static NSString *bucket = @"";
243 [request setAccessKey:accessKey]; 243 [request setAccessKey:accessKey];
244 [request setShouldCompressRequestBody:YES]; 244 [request setShouldCompressRequestBody:YES];
245 [request setAccessPolicy:ASIS3AccessPolicyPublicRead]; // We'll make it public 245 [request setAccessPolicy:ASIS3AccessPolicyPublicRead]; // We'll make it public
246 - [request start]; 246 + [request startSynchronous];
247 success = [[request responseString] isEqualToString:@""]; 247 success = [[request responseString] isEqualToString:@""];
248 GHAssertTrue(success,@"Failed to PUT the gzipped file"); 248 GHAssertTrue(success,@"Failed to PUT the gzipped file");
249 249
@@ -251,7 +251,7 @@ static NSString *bucket = @""; @@ -251,7 +251,7 @@ static NSString *bucket = @"";
251 request = [ASIS3Request requestWithBucket:bucket path:path]; 251 request = [ASIS3Request requestWithBucket:bucket path:path];
252 [request setSecretAccessKey:secretAccessKey]; 252 [request setSecretAccessKey:secretAccessKey];
253 [request setAccessKey:accessKey]; 253 [request setAccessKey:accessKey];
254 - [request start]; 254 + [request startSynchronous];
255 success = [[request responseString] isEqualToString:text]; 255 success = [[request responseString] isEqualToString:text];
256 GHAssertTrue(success,@"Failed to GET the correct data from S3"); 256 GHAssertTrue(success,@"Failed to GET the correct data from S3");
257 257
@@ -283,7 +283,7 @@ static NSString *bucket = @""; @@ -283,7 +283,7 @@ static NSString *bucket = @"";
283 ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path]; 283 ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path];
284 [request setSecretAccessKey:secretAccessKey]; 284 [request setSecretAccessKey:secretAccessKey];
285 [request setAccessKey:accessKey]; 285 [request setAccessKey:accessKey];
286 - [request start]; 286 + [request startSynchronous];
287 GHAssertNil([request error],@"Give up on list request test - failed to upload a file"); 287 GHAssertNil([request error],@"Give up on list request test - failed to upload a file");
288 } 288 }
289 289
@@ -292,7 +292,7 @@ static NSString *bucket = @""; @@ -292,7 +292,7 @@ static NSString *bucket = @"";
292 [listRequest setPrefix:@"test-file"]; 292 [listRequest setPrefix:@"test-file"];
293 [listRequest setSecretAccessKey:secretAccessKey]; 293 [listRequest setSecretAccessKey:secretAccessKey];
294 [listRequest setAccessKey:accessKey]; 294 [listRequest setAccessKey:accessKey];
295 - [listRequest start]; 295 + [listRequest startSynchronous];
296 GHAssertNil([listRequest error],@"Failed to download a list from S3"); 296 GHAssertNil([listRequest error],@"Failed to download a list from S3");
297 success = ([[listRequest bucketObjects] count] == 5); 297 success = ([[listRequest bucketObjects] count] == 5);
298 GHAssertTrue(success,@"List did not contain all files"); 298 GHAssertTrue(success,@"List did not contain all files");
@@ -354,7 +354,7 @@ static NSString *bucket = @""; @@ -354,7 +354,7 @@ static NSString *bucket = @"";
354 [listRequest setPrefix:@"test-file"]; 354 [listRequest setPrefix:@"test-file"];
355 [listRequest setSecretAccessKey:secretAccessKey]; 355 [listRequest setSecretAccessKey:secretAccessKey];
356 [listRequest setAccessKey:accessKey]; 356 [listRequest setAccessKey:accessKey];
357 - [listRequest start]; 357 + [listRequest startSynchronous];
358 GHAssertNil([listRequest error],@"Failed to download a list from S3"); 358 GHAssertNil([listRequest error],@"Failed to download a list from S3");
359 success = ([[listRequest bucketObjects] count] == 0); 359 success = ([[listRequest bucketObjects] count] == 0);
360 GHAssertTrue(success,@"List contained files that should have been deleted"); 360 GHAssertTrue(success,@"List contained files that should have been deleted");
@@ -52,7 +52,7 @@ IMPORTANT @@ -52,7 +52,7 @@ IMPORTANT
52 [[self cancelRequest] setDownloadProgressDelegate:self]; 52 [[self cancelRequest] setDownloadProgressDelegate:self];
53 [[self cancelRequest] setShowAccurateProgress:YES]; 53 [[self cancelRequest] setShowAccurateProgress:YES];
54 NSLog(@"Stress test: Start request %@",[self cancelRequest]); 54 NSLog(@"Stress test: Start request %@",[self cancelRequest]);
55 - [[self cancelRequest] startAsynchronous]; 55 + [[self cancelRequest] startInBackgroundThread];
56 } 56 }
57 } 57 }
58 58
@@ -77,7 +77,7 @@ IMPORTANT @@ -77,7 +77,7 @@ IMPORTANT
77 [self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/ASIHTTPRequest/tests/one_infinite_loop"]]]; 77 [self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/ASIHTTPRequest/tests/one_infinite_loop"]]];
78 if ([[self cancelStartDate] timeIntervalSinceNow] > 0) { 78 if ([[self cancelStartDate] timeIntervalSinceNow] > 0) {
79 NSLog(@"Redirect stress test: Start request %@",[self cancelRequest]); 79 NSLog(@"Redirect stress test: Start request %@",[self cancelRequest]);
80 - [[self cancelRequest] startAsynchronous]; 80 + [[self cancelRequest] startInBackgroundThread];
81 [self performSelector:@selector(cancelRedirectRequest) withObject:nil afterDelay:0.2]; 81 [self performSelector:@selector(cancelRedirectRequest) withObject:nil afterDelay:0.2];
82 } 82 }
83 [createRequestLock unlock]; 83 [createRequestLock unlock];
@@ -114,7 +114,7 @@ IMPORTANT @@ -114,7 +114,7 @@ IMPORTANT
114 [[self cancelRequest] setDelegate:delegate]; 114 [[self cancelRequest] setDelegate:delegate];
115 [[self cancelRequest] setShowAccurateProgress:YES]; 115 [[self cancelRequest] setShowAccurateProgress:YES];
116 NSLog(@"Set delegate stress test: Start request %@",[self cancelRequest]); 116 NSLog(@"Set delegate stress test: Start request %@",[self cancelRequest]);
117 - [[self cancelRequest] startAsynchronous]; 117 + [[self cancelRequest] startInBackgroundThread];
118 [self performSelectorInBackground:@selector(cancelSetDelegateRequest) withObject:nil]; 118 [self performSelectorInBackground:@selector(cancelSetDelegateRequest) withObject:nil];
119 } 119 }
120 [createRequestLock unlock]; 120 [createRequestLock unlock];
@@ -37,6 +37,8 @@ @@ -37,6 +37,8 @@
37 IBOutlet NSButton *resumeButton; 37 IBOutlet NSButton *resumeButton;
38 38
39 IBOutlet NSTextField *bandwidthUsed; 39 IBOutlet NSTextField *bandwidthUsed;
  40 +
  41 + ASIHTTPRequest *bigFetchRequest;
40 } 42 }
41 43
42 - (IBAction)simpleURLFetch:(id)sender; 44 - (IBAction)simpleURLFetch:(id)sender;
@@ -54,4 +56,5 @@ @@ -54,4 +56,5 @@
54 56
55 - (IBAction)throttleBandwidth:(id)sender; 57 - (IBAction)throttleBandwidth:(id)sender;
56 58
  59 +@property (assign, nonatomic) ASIHTTPRequest *bigFetchRequest;
57 @end 60 @end
@@ -30,11 +30,12 @@ @@ -30,11 +30,12 @@
30 30
31 - (IBAction)simpleURLFetch:(id)sender 31 - (IBAction)simpleURLFetch:(id)sender
32 { 32 {
33 - ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/"]] autorelease]; 33 + ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/the_great_american_novel_%28abridged%29.txt"]] autorelease];
34 34
35 //Customise our user agent, for no real reason 35 //Customise our user agent, for no real reason
36 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"]; 36 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
37 - [request start]; 37 + [request setDelegate:self];
  38 + [request startSynchronous];
38 if ([request error]) { 39 if ([request error]) {
39 [htmlSource setString:[[request error] localizedDescription]]; 40 [htmlSource setString:[[request error] localizedDescription]];
40 } else if ([request responseString]) { 41 } else if ([request responseString]) {
@@ -42,6 +43,11 @@ @@ -42,6 +43,11 @@
42 } 43 }
43 } 44 }
44 45
  46 +- (void)requestFinished:(ASIHTTPRequest *)request
  47 +{
  48 + [htmlSource setString:[request responseString]];
  49 +}
  50 +
45 51
46 - (IBAction)URLFetchWithProgress:(id)sender 52 - (IBAction)URLFetchWithProgress:(id)sender
47 { 53 {
@@ -61,7 +67,8 @@ @@ -61,7 +67,8 @@
61 { 67 {
62 [startButton setTitle:@"Start"]; 68 [startButton setTitle:@"Start"];
63 [startButton setAction:@selector(URLFetchWithProgress:)]; 69 [startButton setAction:@selector(URLFetchWithProgress:)];
64 - [networkQueue cancelAllOperations]; 70 + [[self bigFetchRequest] cancel];
  71 + [self setBigFetchRequest:nil];
65 [resumeButton setEnabled:YES]; 72 [resumeButton setEnabled:YES];
66 } 73 }
67 74
@@ -71,18 +78,16 @@ @@ -71,18 +78,16 @@
71 [startButton setTitle:@"Stop"]; 78 [startButton setTitle:@"Stop"];
72 [startButton setAction:@selector(stopURLFetchWithProgress:)]; 79 [startButton setAction:@selector(stopURLFetchWithProgress:)];
73 80
  81 + // Stop any other requests
74 [networkQueue cancelAllOperations]; 82 [networkQueue cancelAllOperations];
75 - [networkQueue setShowAccurateProgress:YES];  
76 - [networkQueue setDownloadProgressDelegate:progressIndicator];  
77 - [networkQueue setDelegate:self];  
78 - [networkQueue setRequestDidFinishSelector:@selector(URLFetchWithProgressComplete:)];  
79 83
80 - ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://trails-network.net/Downloads/MemexTrails_1.0b1.zip"]] autorelease]; 84 + [self setBigFetchRequest:[[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://trails-network.net/Downloads/MemexTrails_1.0b1.zip"]] autorelease]];
81 - [request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip"]]; 85 + [[self bigFetchRequest] setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip"]];
82 - [request setTemporaryFileDownloadPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.download"]]; 86 + [[self bigFetchRequest] setTemporaryFileDownloadPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.download"]];
83 - [request setAllowResumeForFileDownloads:YES]; 87 + [[self bigFetchRequest] setAllowResumeForFileDownloads:YES];
84 - [networkQueue addOperation:request]; 88 + [[self bigFetchRequest] setDidFinishSelector:@selector(URLFetchWithProgressComplete:)];
85 - [networkQueue go]; 89 + [[self bigFetchRequest] setDownloadProgressDelegate:progressIndicator];
  90 + [[self bigFetchRequest] start];
86 } 91 }
87 92
88 - (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request 93 - (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request
@@ -279,5 +284,5 @@ @@ -279,5 +284,5 @@
279 } 284 }
280 285
281 286
282 - 287 +@synthesize bigFetchRequest;
283 @end 288 @end