Skip to content

Commit

Permalink
Set the headers from the APIRequest library.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Aug 30, 2024
1 parent 85b776f commit 4d3e43b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ let package = Package(
dependencies: [
.target(name: "WireGuardC"),
"Common",
"Networking"
],
swiftSettings: [
.define("DEBUG", .when(configuration: .debug))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//

import Foundation
import Networking
import os.log

protocol NetworkProtectionClient {
func getLocations(authToken: String) async -> Result<[NetworkProtectionLocation], NetworkProtectionClientError>
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -330,6 +334,7 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient {

func getServerStatus(authToken: String, serverName: String) async -> Result<NetworkProtectionServerStatus, NetworkProtectionClientError> {
var request = URLRequest(url: serverStatusURL(serverName: serverName))
request.allHTTPHeaderFields = APIRequest.Headers().httpHeaders
request.setValue("bearer \(authToken)", forHTTPHeaderField: "Authorization")
let downloadedData: Data

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d3e43b

Please sign in to comment.