From 4d3e43bcd624c0c9f4ac6ffdee5af170ad61dcc0 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Fri, 30 Aug 2024 16:02:29 -0700 Subject: [PATCH] Set the headers from the APIRequest library. --- Package.swift | 1 + .../Networking/NetworkProtectionClient.swift | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Package.swift b/Package.swift index b0b9da30a..0a677722e 100644 --- a/Package.swift +++ b/Package.swift @@ -323,6 +323,7 @@ let package = Package( dependencies: [ .target(name: "WireGuardC"), "Common", + "Networking" ], swiftSettings: [ .define("DEBUG", .when(configuration: .debug)) diff --git a/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift b/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift index 8f258665d..532a391f9 100644 --- a/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift +++ b/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift @@ -17,6 +17,8 @@ // import Foundation +import Networking +import os.log protocol NetworkProtectionClient { func getLocations(authToken: String) async -> Result<[NetworkProtectionLocation], NetworkProtectionClientError> @@ -244,6 +246,7 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { func getLocations(authToken: String) async -> Result<[NetworkProtectionLocation], NetworkProtectionClientError> { var request = URLRequest(url: locationsURL) + request.allHTTPHeaderFields = APIRequest.Headers().httpHeaders request.setValue("bearer \(authToken)", forHTTPHeaderField: "Authorization") let downloadedData: Data @@ -287,6 +290,7 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { func getServers(authToken: String) async -> Result<[NetworkProtectionServer], NetworkProtectionClientError> { var request = URLRequest(url: serversURL) + request.allHTTPHeaderFields = APIRequest.Headers().httpHeaders request.setValue("bearer \(authToken)", forHTTPHeaderField: "Authorization") let downloadedData: Data @@ -330,6 +334,7 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { func getServerStatus(authToken: String, serverName: String) async -> Result { var request = URLRequest(url: serverStatusURL(serverName: serverName)) + request.allHTTPHeaderFields = APIRequest.Headers().httpHeaders request.setValue("bearer \(authToken)", forHTTPHeaderField: "Authorization") let downloadedData: Data @@ -382,6 +387,7 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { } var request = URLRequest(url: registerKeyURL) + request.allHTTPHeaderFields = APIRequest.Headers().httpHeaders request.setValue("bearer \(authToken)", forHTTPHeaderField: "Authorization") request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.httpMethod = "POST" @@ -444,6 +450,7 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { } var request = URLRequest(url: endpoint) + request.allHTTPHeaderFields = APIRequest.Headers().httpHeaders request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.httpMethod = "POST" request.httpBody = requestBodyData