forked from shadowfacts/Tusker
Fix custom instance domains not being parsed correctly
This commit is contained in:
parent
edb86fc503
commit
b9e359ba83
|
@ -74,13 +74,37 @@ class InstanceSelectorTableViewController: UITableViewController {
|
||||||
loadRecommendedInstances()
|
loadRecommendedInstances()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateSpecificInstance(domain: String) {
|
private func parseURLComponents(input: String) -> URLComponents {
|
||||||
var components = URLComponents(string: domain)!
|
// 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" {
|
if components.scheme != "https" && components.scheme != "http" {
|
||||||
components.scheme = "https"
|
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 client = Client(baseURL: components.url!)
|
||||||
let request = client.getInstance()
|
let request = client.getInstance()
|
||||||
client.run(request) { (response) in
|
client.run(request) { (response) in
|
||||||
|
|
Loading…
Reference in New Issue