2020-09-12 02:50:42 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2021-02-08 20:36:54 +00:00
|
|
|
extension URL {
|
|
|
|
var isHTTPURL: Bool {
|
|
|
|
guard let scheme = scheme else { return false }
|
|
|
|
|
|
|
|
return scheme == "http" || scheme == "https"
|
|
|
|
}
|
2021-02-27 21:29:30 +00: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 20:36:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-12 02:50:42 +00:00
|
|
|
extension URL: Identifiable {
|
|
|
|
public var id: String { absoluteString }
|
|
|
|
}
|