BottleRocketStudios / iOS-Hyperspace

An extremely lightweight wrapper around URLSession to make working with APIs a breeze.
Apache License 2.0
47 stars 17 forks source link

Consider implementing `ExpressibleByStringLiteral` on HTTP header types #120

Closed tylermilner closed 4 years ago

tylermilner commented 4 years ago

This might make it a little nicer when you need to use customer header keys/values.

extension HTTP.HeaderValue: ExpressibleByStringLiteral {

    public init(stringLiteral value: StringLiteralType) {
        self.init(rawValue: value)
    }
}

This would allow you to quickly mix pre-defined and custom header values:

struct APIHeaders {
    static let defaultHeaders: [HTTP.HeaderKey: HTTP.HeaderValue] = [.authorization: "Basic abc123"]
}

Instead of needing to manually init the HTTP.HeaderValue every time:

struct APIHeaders {
    static let defaultHeaders: [HTTP.HeaderKey: HTTP.HeaderValue] = [.authorization: HTTP.HeaderValue(rawValue: "abc123")]
}