diff --git a/Package@swift-4.0.swift b/Package@swift-4.0.swift new file mode 100644 index 0000000..6962b61 --- /dev/null +++ b/Package@swift-4.0.swift @@ -0,0 +1,74 @@ +// swift-tools-version:4.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +/** + * Copyright IBM Corporation 2016, 2017 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +import PackageDescription + +var dependencies: [Package.Dependency] = [ + .package(url: "https://github.com/IBM-Swift/LoggerAPI.git", .upToNextMinor(from: "1.7.0")), + .package(url: "https://github.com/IBM-Swift/BlueSocket.git", .upToNextMinor(from: "0.12.0")), + .package(url: "https://github.com/IBM-Swift/CCurl.git", .upToNextMinor(from: "0.4.0")), + .package(url: "https://github.com/IBM-Swift/BlueSSLService.git", .upToNextMinor(from: "0.12.0")) +] + +var kituraNetDependencies: [Target.Dependency] = [ + .byNameItem(name: "CHTTPParser"), + .byNameItem(name: "LoggerAPI"), + .byNameItem(name: "Socket"), + .byNameItem(name: "CCurl"), + .byNameItem(name: "SSLService") +] + +#if os(Linux) +dependencies.append(contentsOf: [ + .package(url: "https://github.com/IBM-Swift/CEpoll.git", .upToNextMinor(from: "0.1.0")), + .package(url: "https://github.com/IBM-Swift/BlueSignals.git", .upToNextMinor(from: "0.9.0")) + ]) + +kituraNetDependencies.append(contentsOf: [ + .byNameItem(name: "CEpoll"), + .byNameItem(name: "Signals") + ]) +#endif + +let package = Package( + name: "Kitura-net", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "KituraNet", + targets: ["KituraNet"] + ) + ], + dependencies: dependencies, + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "CHTTPParser" + ), + .target( + name: "KituraNet", + dependencies: kituraNetDependencies + ), + .testTarget( + name: "KituraNetTests", + dependencies: ["KituraNet"] + ) + ] +) diff --git a/Sources/KituraNet/FastCGI/FastCGIServerRequest.swift b/Sources/KituraNet/FastCGI/FastCGIServerRequest.swift index f8dfd17..8cfe678 100644 --- a/Sources/KituraNet/FastCGI/FastCGIServerRequest.swift +++ b/Sources/KituraNet/FastCGI/FastCGIServerRequest.swift @@ -53,7 +53,7 @@ public class FastCGIServerRequest : ServerRequest { /// This contains just the path and query parameters starting with '/' /// Use 'urlURL' for the full URL @available(*, deprecated, message: - "This contains just the path and query parameters starting with '/'. use 'urlURL' instead") + "This contains just the path and query parameters starting with '/'. use 'urlURL' instead") public var urlString : String { return requestUri ?? "" } /// The URL from the request in UTF-8 form @@ -64,10 +64,10 @@ public class FastCGIServerRequest : ServerRequest { /// The URL from the request as URLComponents /// URLComponents has a memory leak on linux as of swift 3.0.1. Use 'urlURL' instead @available(*, deprecated, message: - "URLComponents has a memory leak on linux as of swift 3.0.1. use 'urlURL' instead") + "URLComponents has a memory leak on linux as of swift 3.0.1. use 'urlURL' instead") public lazy var urlComponents: URLComponents = { [unowned self] () in return URLComponents(url: self.urlURL, resolvingAgainstBaseURL: false) ?? URLComponents() - }() + }() /// Chunk of body read in by the http_parser, filled by callbacks to onBody private var bodyChunk = BufferList() @@ -200,14 +200,16 @@ public class FastCGIServerRequest : ServerRequest { /// with "HTTP_" prefixed. We want to normalize these out to remove HTTP_ /// and correct the capitilization (first letter of each word capitilized). private func processHttpHeader(_ name: String, value: String, remove: String) { - - var processedName : String = name.substring(from: - name.index(name.startIndex, offsetBy: remove.characters.count)) + #if swift(>=3.2) + var processedName = String(name[name.index(name.startIndex, offsetBy: remove.count)...]) + #else + var processedName = name.substring(from: name.index(name.startIndex, offsetBy: remove.characters.count)) + #endif processedName = processedName.replacingOccurrences(of: "_", with: "-") processedName = processedName.capitalized - headers.append(processedName as String, value: value) + headers.append(processedName, value: value) } /// Parse the server protocol into a major and minor version @@ -219,11 +221,15 @@ public class FastCGIServerRequest : ServerRequest { guard protocolString.lowercased().hasPrefix("http/") && protocolString.characters.count > "http/".characters.count else { - return + return } - - let versionPortion : String = protocolString.substring(from: - protocolString.index(protocolString.startIndex, offsetBy: "http/".characters.count)) + + #if swift(>=3.2) + let versionPortion = String(protocolString[protocolString.index(protocolString.startIndex, offsetBy: "http/".count)...]) + #else + let versionPortion = protocolString.substring(from: protocolString.index(protocolString.startIndex, offsetBy: "http/".characters.count)) + #endif + var decimalPosition : Int = 0 for i in versionPortion.characters { @@ -239,15 +245,23 @@ public class FastCGIServerRequest : ServerRequest { // get major version if decimalPosition > 0 { - let majorPortion : String = versionPortion.substring(to: - versionPortion.index(versionPortion.startIndex, offsetBy: decimalPosition)) + #if swift(>=3.2) + let majorPortion = String(versionPortion[.. decimalPosition { - let minorPortion : String = versionPortion.substring(from: - versionPortion.index(versionPortion.startIndex, offsetBy: decimalPosition + 1)) + #if swift(>=3.2) + let minorPortion = String(versionPortion[versionPortion.index(versionPortion.startIndex, offsetBy: decimalPosition + 1)...]) + #else + let minorPortion = versionPortion.substring(from:versionPortion.index(versionPortion.startIndex, offsetBy: decimalPosition + 1)) + #endif + minorVersion = UInt16(minorPortion) } @@ -256,7 +270,7 @@ public class FastCGIServerRequest : ServerRequest { httpVersionMajor = majorVersion! httpVersionMinor = minorVersion! } - + } @@ -486,8 +500,7 @@ public class FastCGIServerRequest : ServerRequest { return } - } - while true + } while true } catch FastCGI.RecordErrors.invalidVersion { diff --git a/Tests/KituraNetTests/KituraNetTest.swift b/Tests/KituraNetTests/KituraNetTest.swift index 5b366a9..ba284fd 100644 --- a/Tests/KituraNetTests/KituraNetTest.swift +++ b/Tests/KituraNetTests/KituraNetTest.swift @@ -31,28 +31,21 @@ class KituraNetTest: XCTestCase { var port = portDefault static let sslConfig: SSLService.Configuration = { - let path = #file - let sslConfigDir: String - if let range = path.range(of: "/", options: .backwards) { - sslConfigDir = path.substring(to: range.lowerBound) + "/SSLConfig/" - } else { - sslConfigDir = "./SSLConfig/" - } + let sslConfigDir = URL(fileURLWithPath: #file).appendingPathComponent("../SSLConfig") + #if os(Linux) - let certificatePath = sslConfigDir + "certificate.pem" - let keyPath = sslConfigDir + "key.pem" + let certificatePath = sslConfigDir.appendingPathComponent("certificate.pem").standardized.path + let keyPath = sslConfigDir.appendingPathComponent("key.pem").standardized.path return SSLService.Configuration(withCACertificateDirectory: nil, usingCertificateFile: certificatePath, withKeyFile: keyPath, usingSelfSignedCerts: true, cipherSuite: nil) #else - let chainFilePath = sslConfigDir + "certificateChain.pfx" + let chainFilePath = sslConfigDir.appendingPathComponent("certificateChain.pfx").standardized.path return SSLService.Configuration(withChainFilePath: chainFilePath, withPassword: "kitura", usingSelfSignedCerts: true, cipherSuite: nil) #endif }() - private static let initOnce: () = { - PrintLogger.use(colored: true) - }() + private static let initOnce: () = PrintLogger.use(colored: true) func doSetUp() { KituraNetTest.initOnce diff --git a/Tests/KituraNetTests/PrintLogger.swift b/Tests/KituraNetTests/PrintLogger.swift index 9a32965..b65a7fa 100644 --- a/Tests/KituraNetTests/PrintLogger.swift +++ b/Tests/KituraNetTests/PrintLogger.swift @@ -74,6 +74,11 @@ public class PrintLogger: Logger { guard let range = path.range(of: "/", options: .backwards) else { return path } - return path.substring(from: range.upperBound) + + #if swift(>=3.2) + return String(path[range.upperBound...]) + #else + return path.substring(from: range.upperBound) + #endif } } diff --git a/Tests/KituraNetTests/VerifyLinuxTestCount.swift b/Tests/KituraNetTests/VerifyLinuxTestCount.swift index b6a7d86..81648a5 100644 --- a/Tests/KituraNetTests/VerifyLinuxTestCount.swift +++ b/Tests/KituraNetTests/VerifyLinuxTestCount.swift @@ -14,7 +14,10 @@ * limitations under the License. **/ -#if os(OSX) +// Test disabled on Swift 4 for now due to +// https://bugs.swift.org/browse/SR-5684 + +#if os(OSX) && !swift(>=3.2) import XCTest class VerifyLinuxTestCount: XCTestCase {