Showing
5 changed files
with
29 additions
and
4 deletions
| @@ -71,7 +71,6 @@ | @@ -71,7 +71,6 @@ | ||
| 71 | [self setPostData:[NSMutableDictionary dictionary]]; | 71 | [self setPostData:[NSMutableDictionary dictionary]]; |
| 72 | } | 72 | } |
| 73 | [[self postData] setValue:[value description] forKey:key]; | 73 | [[self postData] setValue:[value description] forKey:key]; |
| 74 | - [self setRequestMethod:@"POST"]; | ||
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | - (void)setFile:(NSString *)filePath forKey:(NSString *)key | 76 | - (void)setFile:(NSString *)filePath forKey:(NSString *)key |
| @@ -107,7 +106,6 @@ | @@ -107,7 +106,6 @@ | ||
| 107 | 106 | ||
| 108 | NSDictionary *fileInfo = [NSDictionary dictionaryWithObjectsAndKeys:data, @"data", contentType, @"contentType", fileName, @"fileName", nil]; | 107 | NSDictionary *fileInfo = [NSDictionary dictionaryWithObjectsAndKeys:data, @"data", contentType, @"contentType", fileName, @"fileName", nil]; |
| 109 | [[self fileData] setObject:fileInfo forKey:key]; | 108 | [[self fileData] setObject:fileInfo forKey:key]; |
| 110 | - [self setRequestMethod: @"POST"]; | ||
| 111 | } | 109 | } |
| 112 | 110 | ||
| 113 | - (void)setData:(NSData *)data forKey:(NSString *)key | 111 | - (void)setData:(NSData *)data forKey:(NSString *)key |
| @@ -126,7 +124,6 @@ | @@ -126,7 +124,6 @@ | ||
| 126 | 124 | ||
| 127 | NSDictionary *fileInfo = [NSDictionary dictionaryWithObjectsAndKeys:data, @"data", contentType, @"contentType", fileName, @"fileName", nil]; | 125 | NSDictionary *fileInfo = [NSDictionary dictionaryWithObjectsAndKeys:data, @"data", contentType, @"contentType", fileName, @"fileName", nil]; |
| 128 | [[self fileData] setObject:fileInfo forKey:key]; | 126 | [[self fileData] setObject:fileInfo forKey:key]; |
| 129 | - [self setRequestMethod: @"POST"]; | ||
| 130 | } | 127 | } |
| 131 | 128 | ||
| 132 | - (void)buildPostBody | 129 | - (void)buildPostBody |
| @@ -134,6 +131,9 @@ | @@ -134,6 +131,9 @@ | ||
| 134 | if ([self haveBuiltPostBody]) { | 131 | if ([self haveBuiltPostBody]) { |
| 135 | return; | 132 | return; |
| 136 | } | 133 | } |
| 134 | + if (![[self requestMethod] isEqualToString:@"PUT"]) { | ||
| 135 | + [self setRequestMethod:@"POST"]; | ||
| 136 | + } | ||
| 137 | 137 | ||
| 138 | #if DEBUG_FORM_DATA_REQUEST | 138 | #if DEBUG_FORM_DATA_REQUEST |
| 139 | [self setDebugBodyString:@""]; | 139 | [self setDebugBodyString:@""]; |
| @@ -299,6 +299,7 @@ | @@ -299,6 +299,7 @@ | ||
| 299 | [newRequest setFileData:[[[self fileData] copyWithZone:zone] autorelease]]; | 299 | [newRequest setFileData:[[[self fileData] copyWithZone:zone] autorelease]]; |
| 300 | [newRequest setPostFormat:[self postFormat]]; | 300 | [newRequest setPostFormat:[self postFormat]]; |
| 301 | [newRequest setStringEncoding:[self stringEncoding]]; | 301 | [newRequest setStringEncoding:[self stringEncoding]]; |
| 302 | + [newRequest setRequestMethod:[self requestMethod]]; | ||
| 302 | return newRequest; | 303 | return newRequest; |
| 303 | } | 304 | } |
| 304 | 305 |
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
| 22 | 22 | ||
| 23 | // Automatically set on build | 23 | // Automatically set on build |
| 24 | -NSString *ASIHTTPRequestVersion = @"v1.5-43 2010-02-04"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.5-44 2010-02-04"; |
| 25 | 25 | ||
| 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 27 | 27 |
| @@ -180,6 +180,27 @@ | @@ -180,6 +180,27 @@ | ||
| 180 | 180 | ||
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | +- (void)testPUT | ||
| 184 | +{ | ||
| 185 | + ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/Tests/put_form_data"]]; | ||
| 186 | + [request setRequestMethod:@"PUT"]; | ||
| 187 | + [request setPostValue:@"cheep cheep" forKey:@"hello"]; | ||
| 188 | + [request startSynchronous]; | ||
| 189 | + | ||
| 190 | + NSString *expectedResponse = [[[NSString alloc] initWithBytes:[[request postBody] bytes] length:[[request postBody] length] encoding:[request stringEncoding]] autorelease]; | ||
| 191 | + BOOL success = ([[request responseString] isEqualToString:expectedResponse]); | ||
| 192 | + GHAssertTrue(success,@"Failed to send form data using PUT"); | ||
| 193 | + | ||
| 194 | + // Ensure that other methods still default to POST | ||
| 195 | + request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/Tests/put_form_data"]]; | ||
| 196 | + [request setRequestMethod:@"DELETE"]; | ||
| 197 | + [request setPostValue:@"cheep cheep" forKey:@"hello"]; | ||
| 198 | + [request startSynchronous]; | ||
| 199 | + | ||
| 200 | + success = ([[request responseString] isEqualToString:@"Got POST instead"]); | ||
| 201 | + GHAssertTrue(success,@"Failed to send form data using PUT"); | ||
| 202 | +} | ||
| 203 | + | ||
| 183 | - (void)testCopy | 204 | - (void)testCopy |
| 184 | { | 205 | { |
| 185 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 206 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| @@ -244,6 +244,7 @@ | @@ -244,6 +244,7 @@ | ||
| 244 | GHAssertTrue(success,@"Timeout didn't generate the correct error"); | 244 | GHAssertTrue(success,@"Timeout didn't generate the correct error"); |
| 245 | 245 | ||
| 246 | [ASIHTTPRequest setDefaultTimeOutSeconds:0.0001]; | 246 | [ASIHTTPRequest setDefaultTimeOutSeconds:0.0001]; |
| 247 | + request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 247 | [request startSynchronous]; | 248 | [request startSynchronous]; |
| 248 | 249 | ||
| 249 | success = [[request error] code] == ASIRequestTimedOutErrorType; | 250 | success = [[request error] code] == ASIRequestTimedOutErrorType; |
-
Please register or login to post a comment