Delete unused code in Web module.

This commit is contained in:
Brent Simmons 2024-05-20 22:03:24 -07:00
parent 01e37824a8
commit ad61c01ad4
3 changed files with 0 additions and 120 deletions

View File

@ -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("&amp;")
case "<":
escaped.append("&lt;")
case ">":
escaped.append("&gt;")
case "\"":
escaped.append("&quot;")
case "'":
escaped.append("&apos;")
default:
escaped.append(char)
}
}
return escaped
}
}

View File

@ -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 doesnt 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[..<index])
}
}

View File

@ -1,28 +0,0 @@
//
// NSMutableURLRequest+RSWeb.swift
// RSWeb
//
// Created by Brent Simmons on 12/27/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import Foundation
public extension URLRequest {
@discardableResult mutating func addBasicAuthorization(username: String, password: String) -> 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
}
}