-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURL+Proxy.swift
33 lines (30 loc) · 1.18 KB
/
URL+Proxy.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
extension URL {
/**
Check if the device is proxied for the current URL.
- Note: Simple security check to be used before performing sensitive network requests.
*/
var isProxied: Bool {
guard let proxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() else { return false }
guard let proxies = CFNetworkCopyProxiesForURL(self as CFURL, proxySettings).takeUnretainedValue() as? [[AnyHashable: Any]] else { return false }
// if a proxy exists that isn't "none" then log it and return true
for proxy in proxies {
guard let proxyType = proxy[kCFProxyTypeKey] as? String else { continue }
guard (proxyType as CFString) != kCFProxyTypeNone else { continue }
#if DEBUG
print("Proxy Found: \(proxy))")
#endif
return true
}
return false
}
}
// Obj-C pass through
extension NSURL {
/**
Check if the device is proxied for the current URL.
- Note: Simple security check to be used before performing sensitive network requests.
*/
@objc(isProxied) var _isProxied: Bool {
return (self as URL).isProxied
}
}