2020-09-12 04:50:42 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2021-02-08 21:36:54 +01:00
|
|
|
extension URL {
|
|
|
|
var isHTTPURL: Bool {
|
|
|
|
guard let scheme = scheme else { return false }
|
|
|
|
|
|
|
|
return scheme == "http" || scheme == "https"
|
|
|
|
}
|
2021-02-27 22:29:30 +01:00
|
|
|
|
|
|
|
init?(stringEscapingPath: String) {
|
|
|
|
guard let pathEscaped = stringEscapingPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)
|
|
|
|
else { return nil }
|
|
|
|
|
|
|
|
let httpsColonUnescaped = pathEscaped.replacingOccurrences(
|
|
|
|
of: "https%3A",
|
|
|
|
with: "https:",
|
|
|
|
range: pathEscaped.range(of: "https%3A"))
|
|
|
|
|
|
|
|
self.init(string: httpsColonUnescaped)
|
|
|
|
}
|
2021-02-08 21:36:54 +01:00
|
|
|
}
|
|
|
|
|
2020-09-12 04:50:42 +02:00
|
|
|
extension URL: Identifiable {
|
|
|
|
public var id: String { absoluteString }
|
|
|
|
}
|