Ben Copsey

Reuse authentiction information in the session, removing the need to start the r…

…equest twice for authenticating servers when the authentication info has already been accepted
Big code cleanup - more to come
Bug fixes
@@ -29,8 +29,11 @@ @@ -29,8 +29,11 @@
29 //Dictionary for custom request headers 29 //Dictionary for custom request headers
30 NSMutableDictionary *requestHeaders; 30 NSMutableDictionary *requestHeaders;
31 31
32 - //If usesKeychain is true, network requests will attempt to read credentials from the keychain, and will save them in the keychain when they are successfully presented 32 + //If useKeychainPersistance is true, network requests will attempt to read credentials from the keychain, and will save them in the keychain when they are successfully presented
33 - BOOL usesKeychain; 33 + BOOL useKeychainPersistance;
  34 +
  35 + //If useSessionPersistance is true, network requests will save credentials and reuse for the duration of the session (until clearSession is called)
  36 + BOOL useSessionPersistance;
34 37
35 //When downloadDestinationPath is set, the result of this request will be downloaded to the file at this location 38 //When downloadDestinationPath is set, the result of this request will be downloaded to the file at this location
36 //If downloadDestinationPath is not set, download data will be stored in memory 39 //If downloadDestinationPath is not set, download data will be stored in memory
@@ -72,7 +75,7 @@ @@ -72,7 +75,7 @@
72 CFHTTPAuthenticationRef authentication; 75 CFHTTPAuthenticationRef authentication;
73 76
74 // Credentials associated with the authentication (reused until server says no) 77 // Credentials associated with the authentication (reused until server says no)
75 - CFMutableDictionaryRef credentials; 78 + //CFMutableDictionaryRef credentials;
76 79
77 //Size of the response 80 //Size of the response
78 double contentLength; 81 double contentLength;
@@ -100,6 +103,9 @@ @@ -100,6 +103,9 @@
100 //Called on the delegate when the request fails 103 //Called on the delegate when the request fails
101 SEL didFailSelector; 104 SEL didFailSelector;
102 105
  106 + NSDictionary *responseHeaders;
  107 + NSMutableDictionary *requestCredentials;
  108 +
103 } 109 }
104 110
105 #pragma mark init / dealloc 111 #pragma mark init / dealloc
@@ -162,17 +168,14 @@ @@ -162,17 +168,14 @@
162 #pragma mark http authentication stuff 168 #pragma mark http authentication stuff
163 169
164 // Reads the response headers to find the content length, and returns true if the request needs a username and password (or if those supplied were incorrect) 170 // Reads the response headers to find the content length, and returns true if the request needs a username and password (or if those supplied were incorrect)
165 -- (BOOL)isAuthorizationFailure; 171 +- (BOOL)readResponseHeadersReturningAuthenticationFailure;
166 172
167 // Unlock (unpause) the request thread so it can resume the request 173 // Unlock (unpause) the request thread so it can resume the request
168 // Should be called by delegates when they have populated the authentication information after an authentication challenge 174 // Should be called by delegates when they have populated the authentication information after an authentication challenge
169 - (void)retryWithAuthentication; 175 - (void)retryWithAuthentication;
170 176
171 // Apply authentication information and resume the request after an authentication challenge 177 // Apply authentication information and resume the request after an authentication challenge
172 -- (void)applyCredentialsAndResume; 178 +- (void)attemptToApplyCredentialsAndResume;
173 -  
174 -// Look for somewhere we can get authentication information from  
175 -- (void)applyCredentialsLoad;  
176 179
177 // Customise or overidde this to have a generic error for authentication failure 180 // Customise or overidde this to have a generic error for authentication failure
178 - (NSError *)authenticationError; 181 - (NSError *)authenticationError;
@@ -202,13 +205,19 @@ @@ -202,13 +205,19 @@
202 @property (assign) id delegate; 205 @property (assign) id delegate;
203 @property (assign) NSObject *uploadProgressDelegate; 206 @property (assign) NSObject *uploadProgressDelegate;
204 @property (assign) NSObject *downloadProgressDelegate; 207 @property (assign) NSObject *downloadProgressDelegate;
205 -@property (assign) BOOL usesKeychain; 208 +@property (assign) BOOL useKeychainPersistance;
  209 +@property (assign) BOOL useSessionPersistance;
206 @property (retain) NSString *downloadDestinationPath; 210 @property (retain) NSString *downloadDestinationPath;
207 @property (assign) SEL didFinishSelector; 211 @property (assign) SEL didFinishSelector;
208 @property (assign) SEL didFailSelector; 212 @property (assign) SEL didFailSelector;
209 @property (retain,readonly) NSString *authenticationRealm; 213 @property (retain,readonly) NSString *authenticationRealm;
210 @property (retain) NSError *error; 214 @property (retain) NSError *error;
211 @property (assign,readonly) BOOL complete; 215 @property (assign,readonly) BOOL complete;
  216 +@property (retain) NSDictionary *responseHeaders;
  217 +@property (retain) NSDictionary *requestCredentials;
  218 +
  219 +- (void)saveCredentialsToKeychain:(NSMutableDictionary *)newCredentials;
  220 +- (BOOL)applyCredentials:(NSMutableDictionary *)newCredentials;
212 221
213 222
214 @end 223 @end
This diff is collapsed. Click to expand it.
@@ -9,8 +9,8 @@ @@ -9,8 +9,8 @@
9 9
10 @protocol ASIProgressDelegate 10 @protocol ASIProgressDelegate
11 11
12 -- (void)incrementProgress;  
13 - (void)setDoubleValue:(double)newValue; 12 - (void)setDoubleValue:(double)newValue;
  13 +- (double)doubleValue;
14 - (void)incrementBy:(double)amount; 14 - (void)incrementBy:(double)amount;
15 - (void)setMaxValue:(double)newMax; 15 - (void)setMaxValue:(double)newMax;
16 - (double)maxValue; 16 - (double)maxValue;
@@ -115,7 +115,7 @@ @@ -115,7 +115,7 @@
115 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]] autorelease]; 115 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]] autorelease];
116 [request setDelegate:self]; 116 [request setDelegate:self];
117 [request setDidFinishSelector:@selector(topSecretFetchComplete:)]; 117 [request setDidFinishSelector:@selector(topSecretFetchComplete:)];
118 - [request setUsesKeychain:[keychainCheckbox state]]; 118 + [request setUseKeychainPersistance:[keychainCheckbox state]];
119 [networkQueue addOperation:request]; 119 [networkQueue addOperation:request];
120 120
121 } 121 }
@@ -299,7 +299,7 @@ @@ -299,7 +299,7 @@
299 <real>186</real> 299 <real>186</real>
300 </array> 300 </array>
301 <key>RubberWindowFrame</key> 301 <key>RubberWindowFrame</key>
302 - <string>243 359 1342 819 0 0 1920 1178 </string> 302 + <string>353 264 1342 819 0 0 1920 1178 </string>
303 </dict> 303 </dict>
304 <key>Module</key> 304 <key>Module</key>
305 <string>PBXSmartGroupTreeModule</string> 305 <string>PBXSmartGroupTreeModule</string>
@@ -329,16 +329,16 @@ @@ -329,16 +329,16 @@
329 <key>_historyCapacity</key> 329 <key>_historyCapacity</key>
330 <integer>0</integer> 330 <integer>0</integer>
331 <key>bookmark</key> 331 <key>bookmark</key>
332 - <string>B5AACAC30E3F3DDC00064080</string> 332 + <string>B569CF4A0E41D94E00B57986</string>
333 <key>history</key> 333 <key>history</key>
334 <array> 334 <array>
335 <string>B513D3E90E2BD48A000A50C6</string> 335 <string>B513D3E90E2BD48A000A50C6</string>
336 <string>B513D3EA0E2BD48A000A50C6</string> 336 <string>B513D3EA0E2BD48A000A50C6</string>
337 - <string>B5AAC4CE0E3F1BEF00064080</string>  
338 - <string>B5AAC5460E3F1D8300064080</string>  
339 <string>B5AACA810E3F3D3400064080</string> 337 <string>B5AACA810E3F3D3400064080</string>
340 - <string>B5AACA820E3F3D3400064080</string> 338 + <string>B5127C400E41C09D00D266C2</string>
341 - <string>B5AACAC20E3F3DDC00064080</string> 339 + <string>B5127C540E41C0F300D266C2</string>
  340 + <string>B569CED90E41D71C00B57986</string>
  341 + <string>B569CEDA0E41D71C00B57986</string>
342 </array> 342 </array>
343 <key>prevStack</key> 343 <key>prevStack</key>
344 <array> 344 <array>
@@ -349,8 +349,41 @@ @@ -349,8 +349,41 @@
349 <string>B5ABC8300E24CDE70072F422</string> 349 <string>B5ABC8300E24CDE70072F422</string>
350 <string>B513D4020E2BD48A000A50C6</string> 350 <string>B513D4020E2BD48A000A50C6</string>
351 <string>B513D4030E2BD48A000A50C6</string> 351 <string>B513D4030E2BD48A000A50C6</string>
352 - <string>B5AACA830E3F3D3400064080</string> 352 + <string>B569CDCF0E41C1DC00B57986</string>
353 - <string>B5AACA840E3F3D3400064080</string> 353 + <string>B569CDD50E41C1EE00B57986</string>
  354 + <string>B569CE040E41C8E100B57986</string>
  355 + <string>B569CE050E41C8E100B57986</string>
  356 + <string>B569CE060E41C8E100B57986</string>
  357 + <string>B569CE070E41C8E100B57986</string>
  358 + <string>B569CE130E41CB6200B57986</string>
  359 + <string>B569CE140E41CB6200B57986</string>
  360 + <string>B569CE1C0E41CCC500B57986</string>
  361 + <string>B569CE1D0E41CCC500B57986</string>
  362 + <string>B569CE1E0E41CCC500B57986</string>
  363 + <string>B569CE1F0E41CCC500B57986</string>
  364 + <string>B569CE3A0E41D24C00B57986</string>
  365 + <string>B569CE3B0E41D24C00B57986</string>
  366 + <string>B569CE3C0E41D24C00B57986</string>
  367 + <string>B569CE3D0E41D24C00B57986</string>
  368 + <string>B569CE3E0E41D24C00B57986</string>
  369 + <string>B569CE3F0E41D24C00B57986</string>
  370 + <string>B569CE490E41D2D200B57986</string>
  371 + <string>B569CE4A0E41D2D200B57986</string>
  372 + <string>B569CE4B0E41D2D200B57986</string>
  373 + <string>B569CE510E41D30800B57986</string>
  374 + <string>B569CE5A0E41D3A800B57986</string>
  375 + <string>B569CE610E41D3E300B57986</string>
  376 + <string>B569CE6A0E41D41200B57986</string>
  377 + <string>B569CE730E41D5EB00B57986</string>
  378 + <string>B569CE740E41D5EB00B57986</string>
  379 + <string>B569CE750E41D5EB00B57986</string>
  380 + <string>B569CE760E41D5EB00B57986</string>
  381 + <string>B569CE770E41D5EB00B57986</string>
  382 + <string>B569CE780E41D5EB00B57986</string>
  383 + <string>B569CE790E41D5EB00B57986</string>
  384 + <string>B569CE7A0E41D5EB00B57986</string>
  385 + <string>B569CE800E41D63F00B57986</string>
  386 + <string>B569CEDB0E41D71C00B57986</string>
354 </array> 387 </array>
355 </dict> 388 </dict>
356 <key>SplitCount</key> 389 <key>SplitCount</key>
@@ -364,7 +397,7 @@ @@ -364,7 +397,7 @@
364 <key>Frame</key> 397 <key>Frame</key>
365 <string>{{0, 0}, {1134, 679}}</string> 398 <string>{{0, 0}, {1134, 679}}</string>
366 <key>RubberWindowFrame</key> 399 <key>RubberWindowFrame</key>
367 - <string>243 359 1342 819 0 0 1920 1178 </string> 400 + <string>353 264 1342 819 0 0 1920 1178 </string>
368 </dict> 401 </dict>
369 <key>Module</key> 402 <key>Module</key>
370 <string>PBXNavigatorGroup</string> 403 <string>PBXNavigatorGroup</string>
@@ -384,7 +417,7 @@ @@ -384,7 +417,7 @@
384 <key>Frame</key> 417 <key>Frame</key>
385 <string>{{0, 684}, {1134, 94}}</string> 418 <string>{{0, 684}, {1134, 94}}</string>
386 <key>RubberWindowFrame</key> 419 <key>RubberWindowFrame</key>
387 - <string>243 359 1342 819 0 0 1920 1178 </string> 420 + <string>353 264 1342 819 0 0 1920 1178 </string>
388 </dict> 421 </dict>
389 <key>Module</key> 422 <key>Module</key>
390 <string>XCDetailModule</string> 423 <string>XCDetailModule</string>
@@ -408,9 +441,9 @@ @@ -408,9 +441,9 @@
408 </array> 441 </array>
409 <key>TableOfContents</key> 442 <key>TableOfContents</key>
410 <array> 443 <array>
411 - <string>B5AACA860E3F3D3400064080</string> 444 + <string>B569CDBD0E41C18F00B57986</string>
412 <string>1CE0B1FE06471DED0097A5F4</string> 445 <string>1CE0B1FE06471DED0097A5F4</string>
413 - <string>B5AACA870E3F3D3400064080</string> 446 + <string>B569CDBE0E41C18F00B57986</string>
414 <string>1CE0B20306471E060097A5F4</string> 447 <string>1CE0B20306471E060097A5F4</string>
415 <string>1CE0B20506471E060097A5F4</string> 448 <string>1CE0B20506471E060097A5F4</string>
416 </array> 449 </array>
@@ -544,14 +577,15 @@ @@ -544,14 +577,15 @@
544 <integer>5</integer> 577 <integer>5</integer>
545 <key>WindowOrderList</key> 578 <key>WindowOrderList</key>
546 <array> 579 <array>
547 - <string>B5AACAC40E3F3DDC00064080</string> 580 + <string>B569CDC80E41C18F00B57986</string>
548 - <string>1C78EAAD065D492600B07095</string> 581 + <string>B569CDC90E41C18F00B57986</string>
549 <string>1CD10A99069EF8BA00B06720</string> 582 <string>1CD10A99069EF8BA00B06720</string>
550 <string>B5ABC8410E24CDE70072F422</string> 583 <string>B5ABC8410E24CDE70072F422</string>
  584 + <string>1C78EAAD065D492600B07095</string>
551 <string>/Users/ben/asi-http-request/asi-http-request.xcodeproj</string> 585 <string>/Users/ben/asi-http-request/asi-http-request.xcodeproj</string>
552 </array> 586 </array>
553 <key>WindowString</key> 587 <key>WindowString</key>
554 - <string>243 359 1342 819 0 0 1920 1178 </string> 588 + <string>353 264 1342 819 0 0 1920 1178 </string>
555 <key>WindowToolsV3</key> 589 <key>WindowToolsV3</key>
556 <array> 590 <array>
557 <dict> 591 <dict>
@@ -567,12 +601,14 @@ @@ -567,12 +601,14 @@
567 <key>Dock</key> 601 <key>Dock</key>
568 <array> 602 <array>
569 <dict> 603 <dict>
  604 + <key>BecomeActive</key>
  605 + <true/>
570 <key>ContentConfiguration</key> 606 <key>ContentConfiguration</key>
571 <dict> 607 <dict>
572 <key>PBXProjectModuleGUID</key> 608 <key>PBXProjectModuleGUID</key>
573 <string>1CD0528F0623707200166675</string> 609 <string>1CD0528F0623707200166675</string>
574 <key>PBXProjectModuleLabel</key> 610 <key>PBXProjectModuleLabel</key>
575 - <string></string> 611 + <string>ASIHTTPRequest.m</string>
576 <key>StatusBarVisibility</key> 612 <key>StatusBarVisibility</key>
577 <true/> 613 <true/>
578 </dict> 614 </dict>
@@ -581,7 +617,7 @@ @@ -581,7 +617,7 @@
581 <key>Frame</key> 617 <key>Frame</key>
582 <string>{{0, 0}, {1440, 536}}</string> 618 <string>{{0, 0}, {1440, 536}}</string>
583 <key>RubberWindowFrame</key> 619 <key>RubberWindowFrame</key>
584 - <string>793 360 1440 818 0 0 1920 1178 </string> 620 + <string>396 341 1440 818 0 0 1920 1178 </string>
585 </dict> 621 </dict>
586 <key>Module</key> 622 <key>Module</key>
587 <string>PBXNavigatorGroup</string> 623 <string>PBXNavigatorGroup</string>
@@ -605,7 +641,7 @@ @@ -605,7 +641,7 @@
605 <key>Frame</key> 641 <key>Frame</key>
606 <string>{{0, 541}, {1440, 236}}</string> 642 <string>{{0, 541}, {1440, 236}}</string>
607 <key>RubberWindowFrame</key> 643 <key>RubberWindowFrame</key>
608 - <string>793 360 1440 818 0 0 1920 1178 </string> 644 + <string>396 341 1440 818 0 0 1920 1178 </string>
609 </dict> 645 </dict>
610 <key>Module</key> 646 <key>Module</key>
611 <string>PBXBuildResultsModule</string> 647 <string>PBXBuildResultsModule</string>
@@ -628,14 +664,14 @@ @@ -628,14 +664,14 @@
628 <key>TableOfContents</key> 664 <key>TableOfContents</key>
629 <array> 665 <array>
630 <string>B5ABC8410E24CDE70072F422</string> 666 <string>B5ABC8410E24CDE70072F422</string>
631 - <string>B5AACA880E3F3D3400064080</string> 667 + <string>B569CDBF0E41C18F00B57986</string>
632 <string>1CD0528F0623707200166675</string> 668 <string>1CD0528F0623707200166675</string>
633 <string>XCMainBuildResultsModuleGUID</string> 669 <string>XCMainBuildResultsModuleGUID</string>
634 </array> 670 </array>
635 <key>ToolbarConfiguration</key> 671 <key>ToolbarConfiguration</key>
636 <string>xcode.toolbar.config.buildV3</string> 672 <string>xcode.toolbar.config.buildV3</string>
637 <key>WindowString</key> 673 <key>WindowString</key>
638 - <string>793 360 1440 818 0 0 1920 1178 </string> 674 + <string>396 341 1440 818 0 0 1920 1178 </string>
639 <key>WindowToolGUID</key> 675 <key>WindowToolGUID</key>
640 <string>B5ABC8410E24CDE70072F422</string> 676 <string>B5ABC8410E24CDE70072F422</string>
641 <key>WindowToolIsVisible</key> 677 <key>WindowToolIsVisible</key>
@@ -714,8 +750,6 @@ @@ -714,8 +750,6 @@
714 <array> 750 <array>
715 <string>Name</string> 751 <string>Name</string>
716 <real>277</real> 752 <real>277</real>
717 - <string>Type</string>  
718 - <real>84</real>  
719 <string>Value</string> 753 <string>Value</string>
720 <real>114</real> 754 <real>114</real>
721 <string>Summary</string> 755 <string>Summary</string>
@@ -750,13 +784,13 @@ @@ -750,13 +784,13 @@
750 <key>TableOfContents</key> 784 <key>TableOfContents</key>
751 <array> 785 <array>
752 <string>1CD10A99069EF8BA00B06720</string> 786 <string>1CD10A99069EF8BA00B06720</string>
753 - <string>B5AACA890E3F3D3400064080</string> 787 + <string>B569CDC00E41C18F00B57986</string>
754 <string>1C162984064C10D400B95A72</string> 788 <string>1C162984064C10D400B95A72</string>
755 - <string>B5AACA8A0E3F3D3400064080</string> 789 + <string>B569CDC10E41C18F00B57986</string>
756 - <string>B5AACA8B0E3F3D3400064080</string> 790 + <string>B569CDC20E41C18F00B57986</string>
757 - <string>B5AACA8C0E3F3D3400064080</string> 791 + <string>B569CDC30E41C18F00B57986</string>
758 - <string>B5AACA8D0E3F3D3400064080</string> 792 + <string>B569CDC40E41C18F00B57986</string>
759 - <string>B5AACA8E0E3F3D3400064080</string> 793 + <string>B569CDC50E41C18F00B57986</string>
760 </array> 794 </array>
761 <key>ToolbarConfiguration</key> 795 <key>ToolbarConfiguration</key>
762 <string>xcode.toolbar.config.debugV3</string> 796 <string>xcode.toolbar.config.debugV3</string>
@@ -875,6 +909,8 @@ @@ -875,6 +909,8 @@
875 <key>Dock</key> 909 <key>Dock</key>
876 <array> 910 <array>
877 <dict> 911 <dict>
  912 + <key>BecomeActive</key>
  913 + <true/>
878 <key>ContentConfiguration</key> 914 <key>ContentConfiguration</key>
879 <dict> 915 <dict>
880 <key>PBXProjectModuleGUID</key> 916 <key>PBXProjectModuleGUID</key>
@@ -887,7 +923,7 @@ @@ -887,7 +923,7 @@
887 <key>Frame</key> 923 <key>Frame</key>
888 <string>{{0, 0}, {629, 511}}</string> 924 <string>{{0, 0}, {629, 511}}</string>
889 <key>RubberWindowFrame</key> 925 <key>RubberWindowFrame</key>
890 - <string>281 151 629 552 0 0 1920 1178 </string> 926 + <string>385 95 629 552 0 0 1920 1178 </string>
891 </dict> 927 </dict>
892 <key>Module</key> 928 <key>Module</key>
893 <string>PBXDebugCLIModule</string> 929 <string>PBXDebugCLIModule</string>
@@ -910,17 +946,17 @@ @@ -910,17 +946,17 @@
910 <key>TableOfContents</key> 946 <key>TableOfContents</key>
911 <array> 947 <array>
912 <string>1C78EAAD065D492600B07095</string> 948 <string>1C78EAAD065D492600B07095</string>
913 - <string>B5AACA8F0E3F3D3400064080</string> 949 + <string>B569CDC60E41C18F00B57986</string>
914 <string>1C78EAAC065D492600B07095</string> 950 <string>1C78EAAC065D492600B07095</string>
915 </array> 951 </array>
916 <key>ToolbarConfiguration</key> 952 <key>ToolbarConfiguration</key>
917 <string>xcode.toolbar.config.consoleV3</string> 953 <string>xcode.toolbar.config.consoleV3</string>
918 <key>WindowString</key> 954 <key>WindowString</key>
919 - <string>281 151 629 552 0 0 1920 1178 </string> 955 + <string>385 95 629 552 0 0 1920 1178 </string>
920 <key>WindowToolGUID</key> 956 <key>WindowToolGUID</key>
921 <string>1C78EAAD065D492600B07095</string> 957 <string>1C78EAAD065D492600B07095</string>
922 <key>WindowToolIsVisible</key> 958 <key>WindowToolIsVisible</key>
923 - <false/> 959 + <true/>
924 </dict> 960 </dict>
925 <dict> 961 <dict>
926 <key>Identifier</key> 962 <key>Identifier</key>
This diff is collapsed. Click to expand it.