1
0
mirror of https://github.com/apple/swift-nio-extras.git synced 2025-05-23 05:49:41 +08:00
Rick Newton-Rogers 926c3e19e7
Avoid integer overrun in NIOHTTPResponsiveness ()
We use 8*10^9 in `NIOHTTPResponsiveness` however this number will
overrun the integer size on platforms with 32-bit pointer-width such as
watchOS.

This change drops down to use 1*10^9 on such platforms.
2025-01-31 16:00:41 +00:00

50 lines
1.7 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
public struct ResponsivenessConfig: Codable, Hashable, Sendable {
public var version: Int
public var urls: ResponsivenessConfigURLs
public init(version: Int, urls: ResponsivenessConfigURLs) {
self.version = version
self.urls = urls
}
}
public struct ResponsivenessConfigURLs: Codable, Hashable, Sendable {
public var largeDownloadURL: String
public var smallDownloadURL: String
public var uploadURL: String
enum CodingKeys: String, CodingKey {
case largeDownloadURL = "large_download_url"
case smallDownloadURL = "small_download_url"
case uploadURL = "upload_url"
}
#if _pointerBitWidth(_32)
static var largeDownloadSize: Int { 1_000_000_000 } // 1 * 10^9
#else
static var largeDownloadSize: Int { 8_000_000_000 } // 8 * 10^9
#endif
static var smallDownloadSize: Int { 1 }
public init(scheme: String, authority: String) {
let base = "\(scheme)://\(authority)/responsiveness"
self.largeDownloadURL = "\(base)/download/\(ResponsivenessConfigURLs.largeDownloadSize)"
self.smallDownloadURL = "\(base)/download/\(ResponsivenessConfigURLs.smallDownloadSize)"
self.uploadURL = "\(base)/upload"
}
}