dignifiedquire 2 jaren geleden
bovenliggende
commit
83f6ac1c4d

+ 3 - 3
Podfile

@@ -1,12 +1,12 @@
 target 'deltachat-ios' do
   platform :ios, '11.0'
   use_frameworks!
-  swift_version = '4.2'
+  swift_version = '5'
 
   # ignore all warnings from all dependencies
   inhibit_all_warnings!
 
-  pod 'Swifter'
+  pod 'Swifter', :git => 'https://github.com/httpswift/swifter.git', :branch => 'stable'
   pod 'SwiftLint'
   pod 'SwiftFormat/CLI'
   # pod 'openssl-ios-bitcode'
@@ -25,7 +25,7 @@ end
 target 'DcShare' do
   platform :ios, '11.0'
   use_frameworks!
-  swift_version = '4.2'
+  swift_version = '5'
 
   # ignore all warnings from all dependencies
   inhibit_all_warnings!

+ 9 - 4
Podfile.lock

@@ -35,7 +35,7 @@ DEPENDENCIES:
   - SDWebImageSVGKitPlugin
   - SDWebImageWebPCoder
   - SVGKit (from `https://github.com/SVGKit/SVGKit.git`, branch `3.x`)
-  - Swifter
+  - Swifter (from `https://github.com/httpswift/swifter.git`, branch `stable`)
   - SwiftFormat/CLI
   - SwiftLint
 
@@ -48,7 +48,6 @@ SPEC REPOS:
     - SDWebImage
     - SDWebImageSVGKitPlugin
     - SDWebImageWebPCoder
-    - Swifter
     - SwiftFormat
     - SwiftLint
 
@@ -56,11 +55,17 @@ EXTERNAL SOURCES:
   SVGKit:
     :branch: 3.x
     :git: https://github.com/SVGKit/SVGKit.git
+  Swifter:
+    :branch: stable
+    :git: https://github.com/httpswift/swifter.git
 
 CHECKOUT OPTIONS:
   SVGKit:
     :commit: 8c290ceee19254f6d0da1940201d5efa31b48f9f
     :git: https://github.com/SVGKit/SVGKit.git
+  Swifter:
+    :commit: 1e4f51c92d7ca486242d8bf0722b99de2c3531aa
+    :git: https://github.com/httpswift/swifter.git
 
 SPEC CHECKSUMS:
   CocoaLumberjack: 78abfb691154e2a9df8ded4350d504ee19d90732
@@ -71,10 +76,10 @@ SPEC CHECKSUMS:
   SDWebImageSVGKitPlugin: 06a811c05b9e839982baeb5251d15fe7a79abb82
   SDWebImageWebPCoder: d0dac55073088d24b2ac1b191a71a8f8d0adac21
   SVGKit: 3c8468aab0026048532a3b27a0c81cdd939f0649
-  Swifter: e71dd674404923d7f03ebb03f3f222d1c570bc8e
+  Swifter: aa3514bbb8df8980c118f7bb1b80f2da24e39c2b
   SwiftFormat: 4334264324e20bad415888316165bdc1fc2860bc
   SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
 
-PODFILE CHECKSUM: fa6e9f0530dd141cd710936abd674caa70d383d1
+PODFILE CHECKSUM: 7ff757dacef19f015c1ecf6daabd42e59db7d4b5
 
 COCOAPODS: 1.12.1

+ 25 - 0
Pods/Local Podspecs/Swifter.podspec.json

@@ -0,0 +1,25 @@
+{
+  "name": "Swifter",
+  "version": "1.5.0",
+  "summary": "Tiny http server engine written in Swift programming language.",
+  "homepage": "https://github.com/glock45/swifter",
+  "license": {
+    "type": "Copyright",
+    "file": "LICENSE"
+  },
+  "authors": {
+    "Damian Kołakowski": "kolakowski.damian@gmail.com"
+  },
+  "platforms": {
+    "ios": "9.0",
+    "osx": "10.10",
+    "tvos": "9.0"
+  },
+  "source": {
+    "git": "https://github.com/httpswift/swifter.git",
+    "tag": "1.5.0"
+  },
+  "source_files": "Xcode/Sources/*.{swift}",
+  "swift_versions": "5.0",
+  "swift_version": "5.0"
+}

+ 9 - 4
Pods/Manifest.lock

@@ -35,7 +35,7 @@ DEPENDENCIES:
   - SDWebImageSVGKitPlugin
   - SDWebImageWebPCoder
   - SVGKit (from `https://github.com/SVGKit/SVGKit.git`, branch `3.x`)
-  - Swifter
+  - Swifter (from `https://github.com/httpswift/swifter.git`, branch `stable`)
   - SwiftFormat/CLI
   - SwiftLint
 
@@ -48,7 +48,6 @@ SPEC REPOS:
     - SDWebImage
     - SDWebImageSVGKitPlugin
     - SDWebImageWebPCoder
-    - Swifter
     - SwiftFormat
     - SwiftLint
 
@@ -56,11 +55,17 @@ EXTERNAL SOURCES:
   SVGKit:
     :branch: 3.x
     :git: https://github.com/SVGKit/SVGKit.git
+  Swifter:
+    :branch: stable
+    :git: https://github.com/httpswift/swifter.git
 
 CHECKOUT OPTIONS:
   SVGKit:
     :commit: 8c290ceee19254f6d0da1940201d5efa31b48f9f
     :git: https://github.com/SVGKit/SVGKit.git
+  Swifter:
+    :commit: 1e4f51c92d7ca486242d8bf0722b99de2c3531aa
+    :git: https://github.com/httpswift/swifter.git
 
 SPEC CHECKSUMS:
   CocoaLumberjack: 78abfb691154e2a9df8ded4350d504ee19d90732
@@ -71,10 +76,10 @@ SPEC CHECKSUMS:
   SDWebImageSVGKitPlugin: 06a811c05b9e839982baeb5251d15fe7a79abb82
   SDWebImageWebPCoder: d0dac55073088d24b2ac1b191a71a8f8d0adac21
   SVGKit: 3c8468aab0026048532a3b27a0c81cdd939f0649
-  Swifter: e71dd674404923d7f03ebb03f3f222d1c570bc8e
+  Swifter: aa3514bbb8df8980c118f7bb1b80f2da24e39c2b
   SwiftFormat: 4334264324e20bad415888316165bdc1fc2860bc
   SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
 
-PODFILE CHECKSUM: fa6e9f0530dd141cd710936abd674caa70d383d1
+PODFILE CHECKSUM: 7ff757dacef19f015c1ecf6daabd42e59db7d4b5
 
 COCOAPODS: 1.12.1

File diff suppressed because it is too large
+ 192 - 180
Pods/Pods.xcodeproj/project.pbxproj


+ 1 - 1
Pods/Swifter/README.md

@@ -9,7 +9,7 @@
 Tiny http server engine written in [Swift](https://developer.apple.com/swift/) programming language.
 
 ### Branches
-`* stable` - lands on CocoaPods and others. Supports the latest non-beta XCode and SPM. Stable.
+`* stable` - lands on CocoaPods and others. Supports the latest non-beta Xcode and SPM. Stable.
 
 `* master` - stable branch plus experimental web-framework layer.
 

+ 5 - 5
Pods/Swifter/XCode/Sources/DemoServer.swift

@@ -30,7 +30,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
         }
     }
 
-    server["/magic"] = { .ok(.htmlBody("You asked for " + $0.path)) }
+    server["/magic"] = { .ok(.htmlBody("You asked for " + $0.path), ["XXX-Custom-Header": "value"]) }
 
     server["/test/:param1/:param2"] = { request in
         scopes {
@@ -98,7 +98,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
             guard let name = multipart.name, let fileName = multipart.fileName else { continue }
             response += "Name: \(name) File name: \(fileName) Size: \(multipart.body.count)<br>"
         }
-        return HttpResponse.ok(.htmlBody(response))
+        return HttpResponse.ok(.htmlBody(response), ["XXX-Custom-Header": "value"])
     }
 
     server.GET["/login"] = scopes {
@@ -136,7 +136,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
 
     server.POST["/login"] = { request in
         let formFields = request.parseUrlencodedForm()
-        return HttpResponse.ok(.htmlBody(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
+        return HttpResponse.ok(.htmlBody(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")), ["XXX-Custom-Header": "value"])
     }
 
     server["/demo"] = scopes {
@@ -165,11 +165,11 @@ public func demoServer(_ publicDir: String) -> HttpServer {
     server["/long"] = { _ in
         var longResponse = ""
         for index in 0..<1000 { longResponse += "(\(index)),->" }
-        return .ok(.htmlBody(longResponse))
+        return .ok(.htmlBody(longResponse), ["XXX-Custom-Header": "value"])
     }
 
     server["/wildcard/*/test/*/:param"] = { request in
-        return .ok(.htmlBody(request.path))
+        return .ok(.htmlBody(request.path), ["XXX-Custom-Header": "value"])
     }
 
     server["/stream"] = { _ in

+ 15 - 8
Pods/Swifter/XCode/Sources/Files.swift

@@ -10,19 +10,26 @@ import Foundation
 public func shareFile(_ path: String) -> ((HttpRequest) -> HttpResponse) {
     return { _ in
         if let file = try? path.openForReading() {
-            return .raw(200, "OK", [:], { writer in
+            let mimeType = path.mimeType()
+            var responseHeader: [String: String] = ["Content-Type": mimeType]
+            
+            if let attr = try? FileManager.default.attributesOfItem(atPath: path),
+                let fileSize = attr[FileAttributeKey.size] as? UInt64 {
+                responseHeader["Content-Length"] = String(fileSize)
+            }
+            return .raw(200, "OK", responseHeader, { writer in
                 try? writer.write(file)
                 file.close()
             })
         }
-        return .notFound
+        return .notFound()
     }
 }
 
 public func shareFilesFromDirectory(_ directoryPath: String, defaults: [String] = ["index.html", "default.html"]) -> ((HttpRequest) -> HttpResponse) {
     return { request in
         guard let fileRelativePath = request.params.first else {
-            return .notFound
+            return .notFound()
         }
         if fileRelativePath.value.isEmpty {
             for path in defaults {
@@ -50,19 +57,19 @@ public func shareFilesFromDirectory(_ directoryPath: String, defaults: [String]
                 file.close()
             })
         }
-        return .notFound
+        return .notFound()
     }
 }
 
 public func directoryBrowser(_ dir: String) -> ((HttpRequest) -> HttpResponse) {
     return { request in
         guard let (_, value) = request.params.first else {
-            return HttpResponse.notFound
+            return .notFound()
         }
         let filePath = dir + String.pathSeparator + value
         do {
             guard try filePath.exists() else {
-                return .notFound
+                return .notFound()
             }
             if try filePath.directory() {
                 var files = try filePath.files()
@@ -85,7 +92,7 @@ public func directoryBrowser(_ dir: String) -> ((HttpRequest) -> HttpResponse) {
                     }(request)
             } else {
                 guard let file = try? filePath.openForReading() else {
-                    return .notFound
+                    return .notFound()
                 }
                 return .raw(200, "OK", [:], { writer in
                     try? writer.write(file)
@@ -93,7 +100,7 @@ public func directoryBrowser(_ dir: String) -> ((HttpRequest) -> HttpResponse) {
                 })
             }
         } catch {
-            return HttpResponse.internalServerError
+            return HttpResponse.internalServerError(.text("Internal Server Error"))
         }
     }
 }

+ 15 - 13
Pods/Swifter/XCode/Sources/HttpResponse.swift

@@ -51,8 +51,8 @@ public enum HttpResponseBody {
                     try $0.write(data)
                 })
             case .htmlBody(let body):
-                let serialised = "<html><meta charset=\"UTF-8\"><body>\(body)</body></html>"
-                let data = [UInt8](serialised.utf8)
+                let serialized = "<html><meta charset=\"UTF-8\"><body>\(body)</body></html>"
+                let data = [UInt8](serialized.utf8)
                 return (data.count, {
                     try $0.write(data)
                 })
@@ -61,14 +61,14 @@ public enum HttpResponseBody {
                     try $0.write(data)
                 })
             case .custom(let object, let closure):
-                let serialised = try closure(object)
-                let data = [UInt8](serialised.utf8)
+                let serialized = try closure(object)
+                let data = [UInt8](serialized.utf8)
                 return (data.count, {
                     try $0.write(data)
                 })
             }
         } catch {
-            let data = [UInt8]("Serialisation error: \(error)".utf8)
+            let data = [UInt8]("Serialization error: \(error)".utf8)
             return (data.count, {
                 try $0.write(data)
             })
@@ -80,12 +80,10 @@ public enum HttpResponseBody {
 public enum HttpResponse {
 
     case switchProtocols([String: String], (Socket) -> Void)
-    case ok(HttpResponseBody), created, accepted
+    case ok(HttpResponseBody, [String: String] = [:]), created, accepted
     case movedPermanently(String)
     case movedTemporarily(String)
-    case badRequest(HttpResponseBody?), unauthorized, forbidden, notFound, notAcceptable
-    case tooManyRequests
-    case internalServerError
+    case badRequest(HttpResponseBody?), unauthorized(HttpResponseBody?), forbidden(HttpResponseBody?), notFound(HttpResponseBody? = nil), notAcceptable(HttpResponseBody?), tooManyRequests(HttpResponseBody?), internalServerError(HttpResponseBody?)
     case raw(Int, String, [String: String]?, ((HttpResponseBodyWriter) throws -> Void)? )
 
     public var statusCode: Int {
@@ -133,10 +131,14 @@ public enum HttpResponse {
             for (key, value) in switchHeaders {
                 headers[key] = value
             }
-        case .ok(let body):
+        case .ok(let body, let customHeaders):
+            for (key, value) in customHeaders {
+                headers.updateValue(value, forKey: key)
+            }
             switch body {
             case .json: headers["Content-Type"] = "application/json"
-            case .html: headers["Content-Type"] = "text/html"
+            case .html, .htmlBody: headers["Content-Type"] = "text/html"
+            case .text: headers["Content-Type"] = "text/plain"
             case .data(_, let contentType): headers["Content-Type"] = contentType
             default:break
             }
@@ -157,8 +159,8 @@ public enum HttpResponse {
 
     func content() -> (length: Int, write: ((HttpResponseBodyWriter) throws -> Void)?) {
         switch self {
-        case .ok(let body)             : return body.content()
-        case .badRequest(let body)     : return body?.content() ?? (-1, nil)
+        case .ok(let body, _)          : return body.content()
+        case .badRequest(let body), .unauthorized(let body), .forbidden(let body), .notFound(let body), .tooManyRequests(let body), .internalServerError(let body) : return body?.content() ?? (-1, nil)
         case .raw(_, _, _, let writer) : return (-1, writer)
         default                        : return (-1, nil)
         }

+ 6 - 0
Pods/Swifter/XCode/Sources/HttpRouter.swift

@@ -151,6 +151,12 @@ open class HttpRouter {
             }
 
             if let startStarNode = node.nodes["**"] {
+                if startStarNode.isEndOfRoute {
+                    // ** at the end of a route works as a catch-all
+                    matchedNodes.append(startStarNode)
+                    return
+                }
+
                 let startStarNodeKeys = startStarNode.nodes.keys
                 currentIndex += 1
                 while currentIndex < count, let pathToken = pattern[currentIndex].removingPercentEncoding {

+ 2 - 2
Pods/Swifter/XCode/Sources/HttpServer.swift

@@ -42,10 +42,10 @@ open class HttpServer: HttpServerIO {
     public var delete, patch, head, post, get, put: MethodRoute
 
     public subscript(path: String) -> ((HttpRequest) -> HttpResponse)? {
+        get { return nil }
         set {
             router.register(nil, path: path, handler: newValue)
         }
-        get { return nil }
     }
 
     public var routes: [String] {
@@ -75,10 +75,10 @@ open class HttpServer: HttpServerIO {
         public let method: String
         public let router: HttpRouter
         public subscript(path: String) -> ((HttpRequest) -> HttpResponse)? {
+            get { return nil }
             set {
                 router.register(method, path: path, handler: newValue)
             }
-            get { return nil }
         }
     }
 }

+ 2 - 2
Pods/Swifter/XCode/Sources/HttpServerIO.swift

@@ -8,7 +8,7 @@
 import Foundation
 import Dispatch
 
-public protocol HttpServerIODelegate: class {
+public protocol HttpServerIODelegate: AnyObject {
     func socketConnectionReceived(_ socket: Socket)
 }
 
@@ -112,7 +112,7 @@ open class HttpServerIO {
     }
 
     open func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
-        return ([:], { _ in HttpResponse.notFound })
+        return ([:], { _ in HttpResponse.notFound(nil) })
     }
 
     private func handleConnection(_ socket: Socket) {

+ 3 - 7
Pods/Swifter/XCode/Sources/Socket.swift

@@ -149,13 +149,9 @@ open class Socket: Hashable, Equatable {
     /// - Returns: A buffer containing the bytes read
     /// - Throws: SocketError.recvFailed if unable to read bytes from the socket
     open func read(length: Int) throws -> [UInt8] {
-        var buffer = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: length)
-
-        let bytesRead = try read(into: &buffer, length: length)
-
-        let rv = [UInt8](buffer[0..<bytesRead])
-        buffer.deallocate()
-        return rv
+        return try [UInt8](unsafeUninitializedCapacity: length) { buffer, bytesRead in
+            bytesRead = try read(into: &buffer, length: length)
+        }
     }
 
     static let kBufferLength = 1024

+ 1 - 1
Pods/Swifter/XCode/Sources/WebSockets.swift

@@ -277,7 +277,7 @@ public class WebSocketSession: Hashable, Equatable {
         }
 
         let mask = [try socket.read(), try socket.read(), try socket.read(), try socket.read()]
-        //Read payload all at once, then apply mask (calling `socket.read` byte-by-byte is super slow).
+        // Read payload all at once, then apply mask (calling `socket.read` byte-by-byte is super slow).
         frm.payload = try socket.read(length: Int(len))
         for index in 0..<len {
             frm.payload[Int(index)] ^= mask[Int(index % 4)]

+ 6 - 5
deltachat-ios.xcodeproj/project.pbxproj

@@ -1155,11 +1155,12 @@
 				TargetAttributes = {
 					30E8F20F2447285600CE2C90 = {
 						CreatedOnToolsVersion = 11.4;
+						LastSwiftMigration = "";
 						ProvisioningStyle = Automatic;
 					};
 					7A9FB13F1FB061E2001FEA36 = {
 						CreatedOnToolsVersion = 9.1;
-						LastSwiftMigration = 1030;
+						LastSwiftMigration = "";
 						ProvisioningStyle = Automatic;
 						SystemCapabilities = {
 							com.apple.ApplicationGroups.iOS = {
@@ -2004,7 +2005,7 @@
 					/usr/local/include,
 				);
 				INFOPLIST_FILE = "deltachat-ios/Info.plist";
-				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/Frameworks",
@@ -2077,7 +2078,7 @@
 					/usr/local/include,
 				);
 				INFOPLIST_FILE = "deltachat-ios/Info.plist";
-				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/Frameworks",
@@ -2137,7 +2138,7 @@
 				CLANG_ENABLE_OBJC_WEAK = YES;
 				CODE_SIGN_STYLE = Automatic;
 				INFOPLIST_FILE = "deltachat-iosTests/Info.plist";
-				IPHONEOS_DEPLOYMENT_TARGET = 12.2;
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/Frameworks",
@@ -2161,7 +2162,7 @@
 				CLANG_ENABLE_OBJC_WEAK = YES;
 				CODE_SIGN_STYLE = Automatic;
 				INFOPLIST_FILE = "deltachat-iosTests/Info.plist";
-				IPHONEOS_DEPLOYMENT_TARGET = 12.2;
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/Frameworks",

Some files were not shown because too many files changed in this diff