Re:Alamofire: HTTP Networking in Swift
by Void_ on Thursday September 25, 2014 @04:23PM
(#8369533)
Is there any way to add custom HTTP header yet? This would make for a nice API:
[ Parent
| on HN ]
Re:Alamofire: HTTP Networking in Swift
by matttthompson on Thursday September 25, 2014 @04:36PM
(#8369599)
The short answer: Use the version of `request` that takes a `URLRequestConvertible`, and specify the header fields in that.
The long answer: Custom headers on a per-request basis are a bit of a red herring, from an API design perspective. In reality, most use cases boil down to one of three, which are taken care of in other ways:
- Default headers, such as `User-Agent`, are specified in `NSURLSessionConfiguration -HTTPAdditionalHeaders`. - `Authorization` headers, which are handled by `NSURLCredential` and `NSURLAuthenticationChallenge`. - `Content-Type` headers, which are handled by `ParameterEncoding`.
This is why Alamofire is designed the way it is.