meilisearch-swift
meilisearch-swift copied to clipboard
Give the possibility to provide custom headers
As for #283 the different requests method provide headers as an optionnal parameter.
Nonetheless, if we go up in the stack of calls, no headers are passed to these methods. We should be able to pass them.
For example here:
https://github.com/meilisearch/meilisearch-swift/blob/431d8eefacd9d18e623d19f96cc1b110d675ddfa/Sources/MeiliSearch/Documents.swift#L16-L23
the request.get does not provide the headers that can be passed as an argument here
https://github.com/meilisearch/meilisearch-swift/blob/431d8eefacd9d18e623d19f96cc1b110d675ddfa/Sources/MeiliSearch/Request.swift#L31-L35
We should be able to provide the information.
Two possible solutions this.config can contain the specific headers. In which case we can remove the headers params from the request methods.
Or we provide them as an optional parameter for each method:
public func createIndex(
uid: String,
primaryKey: String? = nil,
headers: [String: String] = [:],
_ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
Indexes.create(uid: uid, primaryKey: primaryKey, config: self.config, completion)
}
I prefer the first option but this also means an additional parameter during the initialisation of a Meilisearch client.
public init(
host: String,
apiKey: String? = nil,
session: URLSessionProtocol? = nil,
request: Request? = nil,
headers: [String: String] = [:]) throws {