From ad61c01ad4a9db4e6ed20402ed799a3c09a2fc5b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 20 May 2024 22:03:24 -0700 Subject: [PATCH] Delete unused code in Web module. --- Web/Sources/Web/String+RSWeb.swift | 39 ------------------- Web/Sources/Web/URL+RSWeb.swift | 53 -------------------------- Web/Sources/Web/URLRequest+RSWeb.swift | 28 -------------- 3 files changed, 120 deletions(-) delete mode 100644 Web/Sources/Web/String+RSWeb.swift delete mode 100755 Web/Sources/Web/URLRequest+RSWeb.swift diff --git a/Web/Sources/Web/String+RSWeb.swift b/Web/Sources/Web/String+RSWeb.swift deleted file mode 100644 index 3bed1da06..000000000 --- a/Web/Sources/Web/String+RSWeb.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// String+RSWeb.swift -// RSWeb -// -// Created by Brent Simmons on 1/13/18. -// Copyright © 2018 Ranchero Software. All rights reserved. -// - -import Foundation - -public extension String { - - /// Escapes special HTML characters. - /// - /// Escaped characters are `&`, `<`, `>`, `"`, and `'`. - var escapedHTML: String { - var escaped = String() - - for char in self { - switch char { - case "&": - escaped.append("&") - case "<": - escaped.append("<") - case ">": - escaped.append(">") - case "\"": - escaped.append(""") - case "'": - escaped.append("'") - default: - escaped.append(char) - } - } - - return escaped - } - -} diff --git a/Web/Sources/Web/URL+RSWeb.swift b/Web/Sources/Web/URL+RSWeb.swift index d9bc8790f..a62d2cc45 100755 --- a/Web/Sources/Web/URL+RSWeb.swift +++ b/Web/Sources/Web/URL+RSWeb.swift @@ -8,40 +8,8 @@ import Foundation -private struct URLConstants { - static let schemeHTTP = "http" - static let schemeHTTPS = "https" - static let prefixHTTP = "http://" - static let prefixHTTPS = "https://" -} - public extension URL { - func isHTTPSURL() -> Bool { - return self.scheme?.lowercased() == URLConstants.schemeHTTPS - } - - func isHTTPURL() -> Bool { - return self.scheme?.lowercased() == URLConstants.schemeHTTP - } - - func isHTTPOrHTTPSURL() -> Bool { - return self.isHTTPSURL() || self.isHTTPURL() - } - - func absoluteStringWithHTTPOrHTTPSPrefixRemoved() -> String? { - // Case-inensitive. Turns http://example.com/foo into example.com/foo - - if isHTTPSURL() { - return absoluteString.stringByRemovingCaseInsensitivePrefix(URLConstants.prefixHTTPS) - } - else if isHTTPURL() { - return absoluteString.stringByRemovingCaseInsensitivePrefix(URLConstants.prefixHTTP) - } - - return nil - } - func appendingQueryItem(_ queryItem: URLQueryItem) -> URL? { appendingQueryItems([queryItem]) } @@ -66,25 +34,4 @@ public extension URL { return URL(string: urlString) } - -} - -private extension String { - - func stringByRemovingCaseInsensitivePrefix(_ prefix: String) -> String { - // Returns self if it doesn’t have the given prefix. - - let lowerPrefix = prefix.lowercased() - let lowerSelf = self.lowercased() - - if (lowerSelf == lowerPrefix) { - return "" - } - if !lowerSelf.hasPrefix(lowerPrefix) { - return self - } - - let index = self.index(self.startIndex, offsetBy: prefix.count) - return String(self[.. Bool { - - // Do this *only* with https. And not even then if you can help it. - - let s = "\(username):\(password)" - guard let d = s.data(using: .utf8, allowLossyConversion: false) else { - return false - } - - let base64EncodedString = d.base64EncodedString() - let authorization = "Basic \(base64EncodedString)" - setValue(authorization, forHTTPHeaderField: HTTPRequestHeader.authorization) - - return true - } -}