Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there any way to add custom HTTP header yet? This would make for a nice API:

  Alamofire.request(.GET, "http://httpbin.org/get")
           .header("custom-header", "value")


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: