mirror of https://github.com/cirruslabs/tart.git
Set User-Agent header for OCI HTTP requests (#478)
* Set User-Agent header for OCI HTTP requests * IORegistry value is actually a NUL-terminated C string * Use sysctl instead of IOKit
This commit is contained in:
parent
9098eaf024
commit
4f70d01dd6
|
|
@ -81,6 +81,15 @@
|
|||
"version" : "1.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-sysctl",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/sersoft-gmbh/swift-sysctl.git",
|
||||
"state" : {
|
||||
"revision" : "71fd64ee84819bb19fbecfb36d5a4503726b6fb7",
|
||||
"version" : "1.6.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftdate",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ let package = Package(
|
|||
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.50.6"),
|
||||
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.3.3"),
|
||||
.package(url: "https://github.com/cfilipov/TextTable", branch: "master"),
|
||||
.package(url: "https://github.com/sersoft-gmbh/swift-sysctl.git", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(name: "tart", dependencies: [
|
||||
|
|
@ -32,6 +33,7 @@ let package = Package(
|
|||
.product(name: "Atomics", package: "swift-atomics"),
|
||||
.product(name: "Sentry", package: "sentry-cocoa"),
|
||||
.product(name: "TextTable", package: "TextTable"),
|
||||
.product(name: "Sysctl", package: "swift-sysctl"),
|
||||
], exclude: [
|
||||
"OCI/Reference/Makefile",
|
||||
"OCI/Reference/Reference.g4",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
import Foundation
|
||||
import Sysctl
|
||||
|
||||
class DeviceInfo {
|
||||
private static var osMemoized: String? = nil
|
||||
private static var modelMemoized: String? = nil
|
||||
|
||||
static var os: String {
|
||||
if let os = osMemoized {
|
||||
return os
|
||||
}
|
||||
|
||||
osMemoized = getOS()
|
||||
|
||||
return osMemoized!
|
||||
}
|
||||
|
||||
static var model: String {
|
||||
if let model = modelMemoized {
|
||||
return model
|
||||
}
|
||||
|
||||
modelMemoized = getModel()
|
||||
|
||||
return modelMemoized!
|
||||
}
|
||||
|
||||
private static func getOS() -> String {
|
||||
let osVersion = ProcessInfo.processInfo.operatingSystemVersion
|
||||
|
||||
return "macOS \(osVersion.majorVersion).\(osVersion.minorVersion).\(osVersion.patchVersion)"
|
||||
}
|
||||
|
||||
private static func getModel() -> String {
|
||||
return SystemControl().hardware.model
|
||||
}
|
||||
}
|
||||
|
|
@ -387,6 +387,9 @@ class Registry {
|
|||
request.addValue(value, forHTTPHeaderField: name)
|
||||
}
|
||||
|
||||
request.setValue("Tart/\(CI.version) (\(DeviceInfo.os); \(DeviceInfo.model))",
|
||||
forHTTPHeaderField: "User-Agent")
|
||||
|
||||
return try await Fetcher.fetch(request, viaFile: viaFile)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue