nerdishbynature / octokit.swift

A Swift API Client for GitHub and GitHub Enterprise
MIT License
501 stars 128 forks source link

make OctoKit struct constructor accept any custom configuration #136

Closed niamster closed 2 years ago

niamster commented 2 years ago

I would like to do smth like

public struct CustomTokenConfiguration: Configuration {
    public var apiEndpoint: String = githubBaseURL
    public var accessToken: String?
    public let errorDomain = OctoKitErrorDomain
    public let authorizationHeader: String? = "token"

    public var customHeaders: [HTTPHeader]? = [
        HTTPHeader(headerField: "cache-control", value: "no-cache"),
    ]

    public init(_ token: String? = nil) {
        accessToken = token
    }
}

For context, it appears that RequestKit uses default cache policy which for some reason does not always plays nicely with GH API.

I didn't dig too much into details of the implementation but disabling local cache always allowed fetch the most up-to date data. I tend to blame the ETag response value as it seems to be present but always empty.

Alternatively, it should be possible to expose cachePolicy of the URLRequest (which is probably better) but I think this is still a good evolution of OctoKit to allow people define custom headers easily.

niamster commented 2 years ago

@pietbrauer are you interested in this one?

niamster commented 2 years ago

No updates, maybe later :)