Skip to content
Browse files

Fix using one too many boundary strings in post data. Some servers (l…

…ike PHP) could handle this, which is why I didn't catch it before. Others (like Rails) would fail. Now compatible with Rails, anyway.

Split username and password setter into two
Added domain for NTLM authentication, will be applied if server asks for it (untested!)
Fix wrong url in tests
  • Loading branch information...
1 parent 7624ef2 commit 652a3a76fde1788ce221b0f7164f4a9b7d345f14 @pokeb committed Aug 10, 2008
Showing with 501 additions and 1,430 deletions.
  1. +1 −0 .gitignore
  2. +6 −3 ASIHTTPRequest.h
  3. +22 −15 ASIHTTPRequest.m
  4. +1 −1 ASIHTTPRequestTests.m
  5. +4 −0 README
  6. +47 −53 asi-http-request.xcodeproj/ben.mode1v3
  7. +420 −1,358 asi-http-request.xcodeproj/ben.pbxuser
View
1 .gitignore
@@ -0,0 +1 @@
+build
View
9 ASIHTTPRequest.h
@@ -60,6 +60,9 @@
//Username and password used for authentication
NSString *username;
NSString *password;
+
+ //Domain used for NTLM authentication
+ NSString *domain;
//Delegate for displaying upload progress (usually an NSProgressIndicator, but you can supply a different object and handle this yourself)
NSObject <ASIProgressDelegate> *uploadProgressDelegate;
@@ -129,9 +132,6 @@
//Add the contents of a local file as a POST variable to the request
- (void)setFile:(NSString *)filePath forKey:(NSString *)key;
-// When set, username and password will be presented for HTTP authentication
-- (void)setUsername:(NSString *)newUsername andPassword:(NSString *)newPassword;
-
#pragma mark get information about this request
- (BOOL)isFinished; //Same thing, for NSOperationQueues to read
@@ -215,6 +215,9 @@
// Remove credentials from the keychain
+ (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm;
+@property (retain) NSString *username;
+@property (retain) NSString *password;
+@property (retain) NSString *domain;
@property (retain,readonly) NSURL *url;
@property (assign) id delegate;
View
37 ASIHTTPRequest.m
@@ -110,15 +110,6 @@ - (void)setFile:(NSString *)filePath forKey:(NSString *)key
[fileData setValue:filePath forKey:key];
}
-- (void)setUsername:(NSString *)newUsername andPassword:(NSString *)newPassword
-{
- [username release];
- username = [newUsername retain];
- [password release];
- password = [newPassword retain];
-}
-
-
#pragma mark get information about this request
@@ -190,25 +181,35 @@ - (void)main
NSData *endItemBoundary = [[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding];
NSEnumerator *e = [postData keyEnumerator];
NSString *key;
+ int i=0;
while (key = [e nextObject]) {
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[postData objectForKey:key] dataUsingEncoding:NSUTF8StringEncoding]];
- [postBody appendData:endItemBoundary];
+ i++;
+ if (i != [postData count] || [fileData count] > 0) { //Only add the boundary if this is not the last item in the post body
+ [postBody appendData:endItemBoundary];
+ }
}
//Adds files to upload
- NSData *contentTypeHeader = [[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *contentBlueprintHeader = [[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding];
e = [fileData keyEnumerator];
+ i=0;
while (key = [e nextObject]) {
NSString *filePath = [fileData objectForKey:key];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n",key,[filePath lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
- [postBody appendData:contentTypeHeader];
+ [postBody appendData:contentBlueprintHeader];
[postBody appendData:[NSData dataWithContentsOfMappedFile:filePath]];
- [postBody appendData:endItemBoundary];
+ i++;
+ if (i != [fileData count]) { //Only add the boundary if this is not the last item in the post body
+ [postBody appendData:endItemBoundary];
+ }
}
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
+ NSString *foo = [[[NSString alloc] initWithBytes:[postBody bytes] length:[postBody length] encoding:NSUTF8StringEncoding] autorelease];
+
// Set the body.
CFHTTPMessageSetBody(request, (CFDataRef)postBody);
@@ -464,6 +465,11 @@ - (BOOL)applyCredentials:(NSMutableDictionary *)newCredentials
- (NSMutableDictionary *)findCredentials
{
NSMutableDictionary *newCredentials = [[[NSMutableDictionary alloc] init] autorelease];
+
+ // Is an account domain needed? (used currently for NTLM only)
+ if (CFHTTPAuthenticationRequiresAccountDomain(requestAuthentication)) {
+ [newCredentials setObject:domain forKey:(NSString *)kCFHTTPAuthenticationAccountDomain];
+ }
// Get the authentication realm
[authenticationRealm release];
@@ -763,8 +769,9 @@ + (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSStr
}
-
-
+@synthesize username;
+@synthesize password;
+@synthesize domain;
@synthesize url;
@synthesize delegate;
@synthesize uploadProgressDelegate;
View
2 ASIHTTPRequestTests.m
@@ -62,7 +62,7 @@ - (void)testOperationQueue
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
NSURL *url;
- url = [[[NSURL alloc] initWithString:@"http:/allseeing-i.com/asi-http-request/tests/first"] autorelease];
+ url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/first"] autorelease];
ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue addOperation:request1];
View
4 README
@@ -26,3 +26,7 @@ ASIHTTPRequest is partly based on code from Apple's ImageClient code samples, so
ASIHTTPRequest is my first open source Objective-C code. I hope to expand the class and example application further (unit tests, maybe even iphone examples...) in the coming months. If you find it helpful, please do get in touch!
+To do:
+NTLM Authentication?
+Digest Authentication?
+PUT / DELETE /GET?
View
100 asi-http-request.xcodeproj/ben.mode1v3
@@ -304,7 +304,7 @@
<real>312</real>
</array>
<key>RubberWindowFrame</key>
- <string>408 248 1342 819 0 0 1920 1178 </string>
+ <string>409 250 1342 819 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXSmartGroupTreeModule</string>
@@ -334,7 +334,7 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
- <string>B5F3B7490E43698300E001FD</string>
+ <string>B567EF2F0E4EDC06001E238F</string>
<key>history</key>
<array>
<string>B5731B8B0E4310180008024F</string>
@@ -345,12 +345,12 @@
<string>B5731E180E43424A0008024F</string>
<string>B5731E330E4344F90008024F</string>
<string>B5731E550E435ADB0008024F</string>
- <string>B5F3B71B0E4367CA00E001FD</string>
- <string>B5F3B71C0E4367CA00E001FD</string>
<string>B5F3B7370E43683600E001FD</string>
- <string>B5F3B7380E43683600E001FD</string>
- <string>B5F3B7440E43698300E001FD</string>
- <string>B5F3B7450E43698300E001FD</string>
+ <string>B5F3B74C0E4378FA00E001FD</string>
+ <string>B567EEF10E4EDA85001E238F</string>
+ <string>B567EF2B0E4EDC06001E238F</string>
+ <string>B567EF2C0E4EDC06001E238F</string>
+ <string>B567EF140E4EDB3D001E238F</string>
</array>
<key>prevStack</key>
<array>
@@ -367,21 +367,16 @@
<string>B5731BC00E4319180008024F</string>
<string>B5731BF60E431A050008024F</string>
<string>B5731D9B0E433A750008024F</string>
- <string>B5F3B7200E4367CA00E001FD</string>
- <string>B5F3B7210E4367CA00E001FD</string>
- <string>B5F3B7220E4367CA00E001FD</string>
- <string>B5F3B7230E4367CA00E001FD</string>
- <string>B5F3B7240E4367CA00E001FD</string>
- <string>B5F3B7250E4367CA00E001FD</string>
- <string>B5F3B7260E4367CA00E001FD</string>
- <string>B5F3B7270E4367CA00E001FD</string>
- <string>B5F3B7280E4367CA00E001FD</string>
- <string>B5F3B7290E4367CA00E001FD</string>
<string>B5F3B7390E43683600E001FD</string>
- <string>B5F3B73A0E43683600E001FD</string>
- <string>B5F3B7460E43698300E001FD</string>
- <string>B5F3B7470E43698300E001FD</string>
- <string>B5F3B7480E43698300E001FD</string>
+ <string>B567EEF40E4EDA85001E238F</string>
+ <string>B567EEF50E4EDA85001E238F</string>
+ <string>B567EEF60E4EDA85001E238F</string>
+ <string>B567EEF70E4EDA85001E238F</string>
+ <string>B567EEF80E4EDA85001E238F</string>
+ <string>B567EEF90E4EDA85001E238F</string>
+ <string>B567EF160E4EDB3D001E238F</string>
+ <string>B567EF2D0E4EDC06001E238F</string>
+ <string>B567EF2E0E4EDC06001E238F</string>
</array>
</dict>
<key>SplitCount</key>
@@ -395,7 +390,7 @@
<key>Frame</key>
<string>{{0, 0}, {1008, 679}}</string>
<key>RubberWindowFrame</key>
- <string>408 248 1342 819 0 0 1920 1178 </string>
+ <string>409 250 1342 819 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
@@ -415,7 +410,7 @@
<key>Frame</key>
<string>{{0, 684}, {1008, 94}}</string>
<key>RubberWindowFrame</key>
- <string>408 248 1342 819 0 0 1920 1178 </string>
+ <string>409 250 1342 819 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@@ -439,9 +434,9 @@
</array>
<key>TableOfContents</key>
<array>
- <string>B5F3B72C0E4367CA00E001FD</string>
+ <string>B567EEE20E4ED8D2001E238F</string>
<string>1CE0B1FE06471DED0097A5F4</string>
- <string>B5F3B72D0E4367CA00E001FD</string>
+ <string>B567EEE30E4ED8D2001E238F</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
@@ -575,16 +570,15 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
- <string>B5F3B7100E4367C800E001FD</string>
- <string>B5F3B72F0E4367CA00E001FD</string>
- <string>B5F3B7300E4367CA00E001FD</string>
+ <string>B567EF0F0E4EDB31001E238F</string>
+ <string>B567EF100E4EDB31001E238F</string>
<string>B5ABC8410E24CDE70072F422</string>
- <string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string>
+ <string>1C78EAAD065D492600B07095</string>
<string>/Users/ben/asi-http-request/asi-http-request.xcodeproj</string>
</array>
<key>WindowString</key>
- <string>408 248 1342 819 0 0 1920 1178 </string>
+ <string>409 250 1342 819 0 0 1920 1178 </string>
<key>WindowToolsV3</key>
<array>
<dict>
@@ -600,12 +594,14 @@
<key>Dock</key>
<array>
<dict>
+ <key>BecomeActive</key>
+ <true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CD0528F0623707200166675</string>
<key>PBXProjectModuleLabel</key>
- <string></string>
+ <string>ASIHTTPRequestTests.m</string>
<key>StatusBarVisibility</key>
<true/>
</dict>
@@ -614,7 +610,7 @@
<key>Frame</key>
<string>{{0, 0}, {1440, 536}}</string>
<key>RubberWindowFrame</key>
- <string>241 -125 1440 818 0 0 1920 1178 </string>
+ <string>287 118 1440 818 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
@@ -638,7 +634,7 @@
<key>Frame</key>
<string>{{0, 541}, {1440, 236}}</string>
<key>RubberWindowFrame</key>
- <string>241 -125 1440 818 0 0 1920 1178 </string>
+ <string>287 118 1440 818 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXBuildResultsModule</string>
@@ -661,18 +657,18 @@
<key>TableOfContents</key>
<array>
<string>B5ABC8410E24CDE70072F422</string>
- <string>B5F3B7080E4367C800E001FD</string>
+ <string>B567EEE40E4ED8D2001E238F</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.buildV3</string>
<key>WindowString</key>
- <string>241 -125 1440 818 0 0 1920 1178 </string>
+ <string>287 118 1440 818 0 0 1920 1178 </string>
<key>WindowToolGUID</key>
<string>B5ABC8410E24CDE70072F422</string>
<key>WindowToolIsVisible</key>
- <false/>
+ <true/>
</dict>
<dict>
<key>FirstTimeWindowDisplayed</key>
@@ -746,21 +742,19 @@
<key>DebugVariablesTableConfiguration</key>
<array>
<string>Name</string>
- <real>348</real>
- <string>Type</string>
- <real>216</real>
+ <real>420</real>
<string>Value</string>
- <real>184</real>
+ <real>255</real>
<string>Summary</string>
- <real>80</real>
+ <real>151</real>
</array>
<key>Frame</key>
<string>{{713, 0}, {851, 339}}</string>
<key>RubberWindowFrame</key>
- <string>238 283 1564 676 0 0 1920 1178 </string>
+ <string>158 131 1564 676 0 0 1920 1178 </string>
</dict>
<key>RubberWindowFrame</key>
- <string>238 283 1564 676 0 0 1920 1178 </string>
+ <string>158 131 1564 676 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXDebugSessionModule</string>
@@ -783,18 +777,18 @@
<key>TableOfContents</key>
<array>
<string>1CD10A99069EF8BA00B06720</string>
- <string>B5F3B7090E4367C800E001FD</string>
+ <string>B567EEE50E4ED8D2001E238F</string>
<string>1C162984064C10D400B95A72</string>
- <string>B5F3B70A0E4367C800E001FD</string>
- <string>B5F3B70B0E4367C800E001FD</string>
- <string>B5F3B70C0E4367C800E001FD</string>
- <string>B5F3B70D0E4367C800E001FD</string>
- <string>B5F3B70E0E4367C800E001FD</string>
+ <string>B567EEE60E4ED8D2001E238F</string>
+ <string>B567EEE70E4ED8D2001E238F</string>
+ <string>B567EEE80E4ED8D2001E238F</string>
+ <string>B567EEE90E4ED8D2001E238F</string>
+ <string>B567EEEA0E4ED8D2001E238F</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.debugV3</string>
<key>WindowString</key>
- <string>238 283 1564 676 0 0 1920 1178 </string>
+ <string>158 131 1564 676 0 0 1920 1178 </string>
<key>WindowToolGUID</key>
<string>1CD10A99069EF8BA00B06720</string>
<key>WindowToolIsVisible</key>
@@ -922,7 +916,7 @@
<key>Frame</key>
<string>{{0, 0}, {636, 839}}</string>
<key>RubberWindowFrame</key>
- <string>121 12 636 880 0 0 1920 1178 </string>
+ <string>138 298 636 880 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXDebugCLIModule</string>
@@ -945,13 +939,13 @@
<key>TableOfContents</key>
<array>
<string>1C78EAAD065D492600B07095</string>
- <string>B5F3B70F0E4367C800E001FD</string>
+ <string>B567EEEB0E4ED8D2001E238F</string>
<string>1C78EAAC065D492600B07095</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.consoleV3</string>
<key>WindowString</key>
- <string>121 12 636 880 0 0 1920 1178 </string>
+ <string>138 298 636 880 0 0 1920 1178 </string>
<key>WindowToolGUID</key>
<string>1C78EAAD065D492600B07095</string>
<key>WindowToolIsVisible</key>
View
1,778 asi-http-request.xcodeproj/ben.pbxuser
420 additions, 1,358 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit 652a3a7

Please sign in to comment.
Something went wrong with that request. Please try again.