Skip to content

Commit

Permalink
Update VPN user agent (#971)
Browse files Browse the repository at this point in the history
Required:

Task/Issue URL: https://app.asana.com/0/1207162258152427/1207484485195971/f
iOS PR: duckduckgo/iOS#3302
macOS PR: duckduckgo/macos-browser#3181
What kind of version bump will this require?: Patch

Description:

This PR updates the VPN client to read from APIRequest.Headers when setting up requests.

Later, the client class should be refactored to use APIRequest across the board for increased testability, but for now I'm reusing a pattern used in a number of places in the clients.
  • Loading branch information
samsymons authored Sep 9, 2024
1 parent 660971f commit b83ccf1
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 b83ccf1

Please sign in to comment.