Stop resetting request method to POST when an unrecognised method is already set
Showing
2 changed files
with
9 additions
and
1 deletions
| @@ -295,7 +295,7 @@ static NSOperationQueue *sharedRequestQueue = nil; | @@ -295,7 +295,7 @@ static NSOperationQueue *sharedRequestQueue = nil; | ||
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | if ([self postLength] > 0) { | 297 | if ([self postLength] > 0) { |
| 298 | - if (![requestMethod isEqualToString:@"POST"] && ![requestMethod isEqualToString:@"PUT"]) { | 298 | + if ([requestMethod isEqualToString:@"GET"] || [requestMethod isEqualToString:@"DELETE"] || [requestMethod isEqualToString:@"HEAD"]) { |
| 299 | [self setRequestMethod:@"POST"]; | 299 | [self setRequestMethod:@"POST"]; |
| 300 | } | 300 | } |
| 301 | [self addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%llu",[self postLength]]]; | 301 | [self addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%llu",[self postLength]]]; |
| @@ -125,6 +125,14 @@ | @@ -125,6 +125,14 @@ | ||
| 125 | BOOL success = [[request responseString] isEqualToString:method]; | 125 | BOOL success = [[request responseString] isEqualToString:method]; |
| 126 | GHAssertTrue(success,@"Failed to set the request method correctly"); | 126 | GHAssertTrue(success,@"Failed to set the request method correctly"); |
| 127 | } | 127 | } |
| 128 | + | ||
| 129 | + // Test to ensure we don't change the request method when we have an unrecognised method already set | ||
| 130 | + ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | ||
| 131 | + [request setRequestMethod:@"FINK"]; | ||
| 132 | + [request appendPostData:[@"King" dataUsingEncoding:NSUTF8StringEncoding]]; | ||
| 133 | + [request buildPostBody]; | ||
| 134 | + BOOL success = [[request requestMethod] isEqualToString:@"FINK"]; | ||
| 135 | + GHAssertTrue(success,@"Erroneously changed request method"); | ||
| 128 | } | 136 | } |
| 129 | 137 | ||
| 130 | - (void)testHTTPVersion | 138 | - (void)testHTTPVersion |
-
Please register or login to post a comment