Skip to content

Commit

Permalink
fix: adding more info to user-agent header (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
5d authored Aug 22, 2024
1 parent 4592179 commit 6930d5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions Sources/AWSAppSyncApolloExtensions/Utilities/PackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


import Foundation
import Apollo
#if canImport(WatchKit)
import WatchKit
#elseif canImport(UIKit)
Expand All @@ -31,8 +32,9 @@ class PackageInfo {
let device = UIDevice.current
return (name: device.systemName, version: device.systemVersion)
#else
let osVersion = ProcessInfo.processInfo.operatingSystemVersion
return (name: "macOS",
version: ProcessInfo.processInfo.operatingSystemVersionString)
version: "\(osVersion.majorVersion).\(osVersion.minorVersion).\(osVersion.patchVersion)")
#endif
}()

Expand All @@ -53,11 +55,12 @@ class PackageInfo {
static var userAgent: String {
get async {
let (name, version) = await Self.os
let compilerInfo = "lang/swift/\(swiftVersion)"
let osInfo = "os/\(name)/\(version)"
let libInfo = "lib/aws-appsync-apollo-extensions-swift/\(Self.version)"
let compilerInfo = "lang/swift#\(swiftVersion)"
let osInfo = "os/\(name)#\(version)"
let libInfo = "lib/aws-appsync-apollo-extensions-swift#\(Self.version)"
let dependenciesInfo = "md/apollo#\(Constants.ApolloVersion)"

return "UA/2.0 \(compilerInfo) \(osInfo) \(libInfo)"
return "UA/2.0 \(compilerInfo) \(osInfo) \(libInfo) \(dependenciesInfo)"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class PackageInfoTests: XCTestCase {
func testUserAgentHasCorrectFormat() async throws {
let format = try Regex(
"^UA/2\\.0 " +
"lang/swift/\\d+\\.\\d+(?:\\.\\d+)? " +
"os/iOS|macOS|watchOS/\\d+\\.\\d+(?:\\.\\d+)? " +
"lib/aws-appsync-apollo-extensions-swift/\\d+\\.\\d+\\.\\d+$"
"lang/swift#\\d+\\.\\d+(?:\\.\\d+)? " +
"os/(?:iOS|macOS|watchOS)#\\d+\\.\\d+(?:\\.\\d+)? " +
"lib/aws-appsync-apollo-extensions-swift#\\d+\\.\\d+\\.\\d+ " +
"md/apollo#\\d+\\.\\d+\\.\\d+$"
)
let userAgent = await PackageInfo.userAgent
let matches = userAgent.ranges(of: format)
Expand Down

0 comments on commit 6930d5a

Please sign in to comment.