forked from shadowfacts/Tusker
Fix custom instance domains not being parsed correctly
This commit is contained in:
parent
edb86fc503
commit
b9e359ba83
|
@ -74,12 +74,36 @@ class InstanceSelectorTableViewController: UITableViewController {
|
|||
loadRecommendedInstances()
|
||||
}
|
||||
|
||||
private func updateSpecificInstance(domain: String) {
|
||||
var components = URLComponents(string: domain)!
|
||||
private func parseURLComponents(input: String) -> URLComponents {
|
||||
// we can't just use the URLComponents(string:) initializer, because when given just a domain (w/o protocol), it interprets it as the path
|
||||
var input = input
|
||||
var components = URLComponents()
|
||||
// extract protocol
|
||||
if input.contains("://") {
|
||||
let parts = input.components(separatedBy: "://")
|
||||
components.scheme = parts.first!
|
||||
input = parts.last!
|
||||
}
|
||||
if components.scheme != "https" && components.scheme != "http" {
|
||||
components.scheme = "https"
|
||||
}
|
||||
components.path = "/"
|
||||
// drop path
|
||||
if input.contains("/") {
|
||||
let parts = input.components(separatedBy: "/")
|
||||
input = parts.first!
|
||||
}
|
||||
// parse port
|
||||
if input.contains(":") {
|
||||
let parts = input.components(separatedBy: ":")
|
||||
input = parts.first!
|
||||
components.port = Int(parts.last!)
|
||||
}
|
||||
components.host = input
|
||||
return components
|
||||
}
|
||||
|
||||
private func updateSpecificInstance(domain: String) {
|
||||
let components = parseURLComponents(input: domain)
|
||||
|
||||
let client = Client(baseURL: components.url!)
|
||||
let request = client.getInstance()
|
||||
|
|
Loading…
Reference in New Issue