-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ubf adds proxy and dev setting #90
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
09005be
UBF: Removes not needed/wanted default header
choli 7323342
Adds possibility to add a proxy to session config
choli 93f69bf
Adds dev tool & helper to easily set a proxy
choli 2a8089c
UBL: Adds possibility to add local proxy
choli c778731
UBK: Addresses code review remarks
choli 0fb59c4
UBK: Deactivate proxy after a day
choli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,15 @@ public struct DevToolsView: View { | |
CacheDevTools.clearCache(cache) | ||
} | ||
} | ||
Section(header: Text("Proxy settings")) { | ||
Toggle("Start Proxy", isOn: Binding(get: { Self.enableNetworkingProxySettings }, set: { Self.enableNetworkingProxySettings = $0 })) | ||
TextField("Host", text: Binding(get: { Self.proxySettingsHost ?? "" }, set: { Self.proxySettingsHost = $0 })) | ||
TextField("Port", text: Binding(get: { | ||
Self.proxySettingsPort != nil ? String(Self.proxySettingsPort!) : "" | ||
}, set: { | ||
Self.proxySettingsPort = Int($0) | ||
})) | ||
} | ||
|
||
#if !targetEnvironment(simulator) | ||
ShareDocumentsView() | ||
|
@@ -188,4 +197,13 @@ public struct DevToolsView: View { | |
|
||
@UBUserDefault(key: "io.openmobilemaps.debug.rastertiles.enabled", defaultValue: false) | ||
public static var mapRasterTilesDebugOverlay: Bool | ||
|
||
@UBUserDefault(key: "ubkit.devtools.proxy.enabled.key", defaultValue: false) | ||
public static var enableNetworkingProxySettings: Bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Damit man das nicht aus Versehen für immer laufe lässt, zwei Vorschläge:
|
||
|
||
@UBUserDefault(key: "ubkit.devtools.proxy.host.key", defaultValue: nil) | ||
public static var proxySettingsHost: String? | ||
|
||
@UBUserDefault(key: "ubkit.devtools.proxy.port.key", defaultValue: nil) | ||
public static var proxySettingsPort: Int? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// ProxyDevTools.swift | ||
// | ||
// | ||
// Created by Sandro Kolly on 10.05.2024. | ||
// | ||
|
||
import UBFoundation | ||
import UIKit | ||
|
||
class UBDevToolsProxyHelper { | ||
static let shared = UBDevToolsProxyHelper() | ||
|
||
fileprivate private(set) var proxy: Proxy? = nil | ||
|
||
func setProxy(host: String, port: Int, username: String?, password: String?) { | ||
proxy = Proxy(host: host, port: port, username: username, password: password) | ||
} | ||
|
||
fileprivate struct Proxy: UBURLSessionConfigurationProxy { | ||
var host: String | ||
var port: Int | ||
var username: String? | ||
var password: String? | ||
} | ||
} | ||
|
||
public class UBFriendlyEvaluator: UBServerTrustEvaluator { | ||
public func evaluate(_ trust: SecTrust, forHost host: String) throws { | ||
// on purpose not throwing, we allow it all | ||
} | ||
} | ||
|
||
@available(iOS 14.0, *) | ||
public extension Networking { | ||
/// This is a copy of the sharedSession including the proxy and friendly trust settings | ||
static let friendlySharedSession: UBURLSession = { | ||
guard DevToolsView.enableNetworkingProxySettings else { return Networking.sharedSession } | ||
|
||
let queue = OperationQueue() | ||
queue.name = "Friendly UBURLSession Shared" | ||
queue.qualityOfService = .userInitiated | ||
|
||
let proxy: UBDevToolsProxyHelper.Proxy? | ||
if let host = DevToolsView.proxySettingsHost, host.isEmpty == false, | ||
let port = DevToolsView.proxySettingsPort { | ||
proxy = UBDevToolsProxyHelper.Proxy(host: host, port: port) | ||
} else if let devProy = UBDevToolsProxyHelper.shared.proxy { | ||
proxy = devProy | ||
} else { | ||
proxy = nil | ||
} | ||
|
||
let configuration = UBURLSessionConfiguration(defaultServerTrust: UBFriendlyEvaluator(), proxy: proxy) | ||
configuration.sessionConfiguration.networkServiceType = .responsiveData | ||
return UBURLSession(configuration: configuration, delegateQueue: queue) | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// UBURLSessionConfigurationProxy.swift | ||
// | ||
// | ||
// Created by Sandro Kolly on 07.05.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A protocol to set a proxy on the UBURLSessionConfiguration | ||
/// | ||
/// Currently only basic auth is supported for proxy. The auth header is set in the configuration httpAdditionalHeaders. | ||
/// If the proxy needs a different auth, this can be overwritten in the session, which takes priority over the httpAdditionalHeaders. | ||
public protocol UBURLSessionConfigurationProxy { | ||
var host: String { get } | ||
var port: Int { get } | ||
var username: String? { get } | ||
var password: String? { get } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Den Restart brauchen wir hier nicht, weil man sowieso Save and exit klickt, oder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genau, hatte ich ursprünglich drin, bis ich den "Speichern" Button gesehen habe.