AFNetworking/AFNetworking — pull request #885 by sartak (2013-03-29 17:13:54+00:00)
Title: Add optional headers parameter to getPath, postPath, etc.

Hi!

Thanks very much for writing AFNetworking. :)

My app is talking to a RESTful API and oftentimes that means sending additional headers for individual requests. Headers like If-Match only make sense for a specific request (as opposed to all requests that an AFHTTPClient will make). I certainly could have called `setDefaultHeader:value:` before the request, then after firing off the request, call it again passing `nil` for the value to clear that default. But that lacks elegance in a big way.

I'm not the first with this need: http://stackoverflow.com/questions/12667838/setting-non-default-http-headers-with-afhttpclient the accepted answer says to make a different subclass of AFHTTPClient for each resource (yikes!!)

So, to make that answer and my app better, what this pull requests adds is variants of getPath, postPath, putPath, deletePath, and patchPath, all of which have an additional `headers:(NSDictionary *)headers` parameter after `parameters:`.

There were two ways to implement this: either adding second copies of each of the five methods, tweaking them to add headers, or making the original `headers`-less variants call the new variants, passing `nil` for `headers:`. Ordinarily I would have chosen the latter, but in this case I chose the former because the existing `getPath`, `postPath`, etc. could have easily been written to call a private `requestPath` that has a method parameter, but they're not written that way (whether as an optimization or for debugging, I don't know). In other words, I opted to match the existing tradeoffs.

Please excuse and inform me of any mistakes I've made here, this is my first time contributing to an Obj-C project :)

Cheers,
Shawn