Set request attribution to user

This commit is contained in:
Shadowfacts 2021-09-28 20:20:08 -04:00
parent 13462d2307
commit 8c53685d21
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 20 additions and 0 deletions

View File

@ -201,6 +201,9 @@ class BrowserWebViewController: UIViewController {
}
}
}
if #available(iOS 15.0, *) {
task!.attribution = .user
}
task!.resume()
}

View File

@ -17,6 +17,17 @@ public class GeminiDataTask {
private let completion: Completion
private var state = State.unstarted
private let connection: NWConnection
// todo: remove stupid hack when deployment target is >= iOS 15/macOS 12
private var _attribution: Any? = nil
@available(iOS 15.0, *)
public var attribution: NWParameters.Attribution {
get {
_attribution as? NWParameters.Attribution ?? .developer
}
set {
_attribution = newValue
}
}
public init(request: GeminiRequest, completion: @escaping Completion) {
self.request = request
@ -25,6 +36,10 @@ public class GeminiDataTask {
let endpoint: NWEndpoint = .hostPort(host: NWEndpoint.Host(request.url.host!), port: NWEndpoint.Port(rawValue: port)!)
self.connection = NWConnection(to: endpoint, using: .gemini)
if #available(iOS 15.0, *) {
connection.parameters.attribution = attribution
}
self.connection.stateUpdateHandler = { (newState) in
switch newState {
case .ready:

View File

@ -8,6 +8,8 @@
import Network
extension NWParameters {
/// An NWParameters configured with the GeminiProtocol and appropriate TLS options.
/// This property always returns a new NWParameters instance.
static var gemini: NWParameters {
let tlsOptions = geminiTLSOptions
let tcpOptions = NWProtocolTCP.Options()