AFNetworking/AFNetworking — pull request #161 by kcharwood (2012-01-05 16:39:33+00:00)
Title: Cancel HTTP Operations based on Path while ignoring URL Parameters

This pull requests contains a new feature that makes it a little bit easier to cancel HTTP operations when using the convenience methods (getPath, postPath, etc) while also ignoring URL parameters in a GET a request. With the current canceling mechanism in `AFHTTPClient`, you are responsible for maintaining a specific URL in order to cancel it. In the case of a GET request, you may not know the specific parameters that were sent across, but you may still want to cancel any operation that is currently outbound with that specific path.

I have added the following method to AFHTTPClient:

```objective-c
- (void)cancelHTTPOperationsWithMethod:(NSString *)method andPath:(NSString*)path;
```

This method takes in the HTTP Method type, and the API path to match on. Under the hood, I am stripping off all parameters of any HTTP Operations, and looking at just the baseURL+path of existing operations.

I have included a use case below. Here, we have a situation where I am wanting to quickly auto populate a list with people that match a search, and I want to update the list as the user continues to type in new characters. In this case, I can quickly cancel an existing request while kicking off a new one everytime a new search is initiated, all without having to worry about the parameters that were passed along with the earlier requests.

```objective-c
- (void)autoCompletePeopleWithString:(NSString*)string
success:(void (^)(NSArray *people))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure{

[self cancelHTTPOperationsWithMethod:@"GET"
andPath:@"people"];

NSDictionary * parameters = [NSDictionary dictionaryWithObjectsAndKeys:string,@"name", nil];

[self getPath:@"people"
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray * jsonArray = [responseObject objectForKey:@"people"];
NSMutableArray * peopleArray = [NSMutableArray arrayWithCapacity:[jsonArray count]];
for (NSDictionary * personDictionary in jsonArray){
KHPerson * person = [KHPerson personWithDictionary:personDictionary];
[peopleArray addObject:person];
}
success([NSArray arrayWithArray:peopleArray]);
}
failure:failure];
}

```