From dd8a2bc491936eea0e76941dd04646702625f46b Mon Sep 17 00:00:00 2001 From: Borut Tomazin Date: Mon, 27 May 2024 12:01:14 +0200 Subject: [PATCH] Headers update. --- Sources/LinkedIn/API/LinkedInAPI.swift | 6 +++--- Sources/LinkedIn/Core/HttpClient.swift | 13 ++----------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Sources/LinkedIn/API/LinkedInAPI.swift b/Sources/LinkedIn/API/LinkedInAPI.swift index 3da5504..f3476c2 100644 --- a/Sources/LinkedIn/API/LinkedInAPI.swift +++ b/Sources/LinkedIn/API/LinkedInAPI.swift @@ -40,7 +40,7 @@ public extension LinkedInAPI { let response = try await client.request( method: "POST", url: url, - headers: [.init(name: "Content-Type", value: "application/x-www-form-urlencoded")] + headers: ["Content-Type": "application/x-www-form-urlencoded"] ) let decoder = JSONDecoder() @@ -61,7 +61,7 @@ public extension LinkedInAPI { let response = try await client.request( method: "GET", url: url, - headers: [.init(name: "Authorization", value: "Bearer \(request.token)")] + headers: ["Authorization": "Bearer \(request.token)"] ) let decoder = JSONDecoder() @@ -78,7 +78,7 @@ public extension LinkedInAPI { let response = try await client.request( method: "GET", url: url, - headers: [.init(name: "Authorization", value: "Bearer \(request.token)")] + headers: ["Authorization": "Bearer \(request.token)"] ) let decoded = try JSONDecoder().decode(LinkedInEmailResponse.self, from: response) diff --git a/Sources/LinkedIn/Core/HttpClient.swift b/Sources/LinkedIn/Core/HttpClient.swift index c00327a..cbaa7f8 100644 --- a/Sources/LinkedIn/Core/HttpClient.swift +++ b/Sources/LinkedIn/Core/HttpClient.swift @@ -9,12 +9,10 @@ import Foundation struct HttpClient { - func request(method: String, url: URL, headers: [Header]) async throws -> Data { + func request(method: String, url: URL, headers: [String: String]?) async throws -> Data { var urlRequest = URLRequest(url: url) urlRequest.httpMethod = method - headers.forEach { - urlRequest.setValue($0.value, forHTTPHeaderField: $0.name) - } + urlRequest.allHTTPHeaderFields = headers let (data, response) = try await URLSession.shared.data(for: urlRequest) @@ -26,10 +24,3 @@ struct HttpClient { return data } } - -extension HttpClient { - struct Header { - let name: String - let value: String - } -}