RFC: Alamofire HTTPHeaders API

In an attempt to help users with sometimes unknown HTTP headers and provide a consistent API across the system networking type, I've created a PR that adds a concrete HTTPHeaders type, as well as a simple HTTPHeader type.

This implementation seeks a balance between convenient high-level APIs, simple implementation, and integration with URLRequest, HTTPURLResponse, and URLSessionConfiguration, which all have different property names and sometimes different types for the headers. The HTTPHeaders type allows conversion to and from [String: String] to integrate with these APIs.

In addition, HTTPHeaders allows for simple high-level usage, being both ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral, giving us an API like this:

let headers: HTTPHeaders = ["Content-Type": "application/json"]

and, with the right static constructors:

let headers: HTTPHeaders = [.contentType("application/json")]

So this RFC seek input on the API surface offered and desired features for such a type. While code level comments can be left on the PR, API or theoretical discussions are likely better here.

1 Like