Skip to content

Commit

Permalink
Update for swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
OrkhanAlikhanov committed Nov 10, 2019
1 parent 0e0c1e2 commit 440a6dc
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,6 @@ playground.xcworkspace
# ignore cocoapod generated files
Pods
Podfile.lock
HttpSwift.xcworkspace
HttpSwift.xcworkspace
Package.resolved
.swiftpm
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

21 changes: 3 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,12 @@ matrix:
- sourceline: 'deb [trusted=yes] http://apt.orkhanalikhanov.com ./'
packages:
- libressl
install: eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
env: SWIFT_VERSION=5.0
install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
script: env LD_LIBRARY_PATH='/usr/local/lib:/usr/local/opt/libressl/lib:$LD_LIBRARY_PATH' swift test

- os: osx
osx_image: xcode11.2
dist: trusty
sudo: required
env: ACTION=test PLATFORM=Mac DESTINATION='platform=OS X'
script: set -o pipefail && xcodebuild -project HttpSwift.xcodeproj -scheme HttpSwift -destination "$DESTINATION" $ACTION | xcpretty

- os: osx
osx_image: xcode11.2
dist: trusty
sudo: required
env: ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 11'
script: set -o pipefail && xcodebuild -project HttpSwift.xcodeproj -scheme HttpSwift -destination "$DESTINATION" $ACTION | xcpretty

- os: osx
osx_image: xcode11.2
dist: trusty
sudo: required
env: ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV'
script: set -o pipefail && xcodebuild -project HttpSwift.xcodeproj -scheme HttpSwift -destination "$DESTINATION" $ACTION | xcpretty

script: set -o pipefail && xcodebuild -scheme RequestSwift -destination "platform=OS X" test | xcpretty && xcodebuild -scheme RequestSwift -destination "platform=iOS Simulator,name=iPhone 11" test | xcpretty && xcodebuild -scheme RequestSwift -destination "platform=tvOS Simulator,name=Apple TV" test | xcpretty
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "BiAtoms/Socket.swift" ~> 2.2
github "BiAtoms/Socket.swift" ~> 2.3.0
5 changes: 3 additions & 2 deletions Http.swift.podspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
Pod::Spec.new do |s|
s.name = 'Http.swift'
s.version = '2.1.2'
s.version = '2.2.0'
s.summary = 'A tiny http server engine written in swift.'
s.homepage = 'https://github.com/BiAtoms/Http.swift'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Orkhan Alikhanov' => '[email protected]' }
s.source = { :git => 'https://github.com/BiAtoms/Http.swift.git', :tag => s.version.to_s }
s.module_name = 'HttpSwift'

s.swift_versions = ['5.0']
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
s.tvos.deployment_target = '9.0'
s.source_files = 'Sources/*.swift'
s.dependency 'Socket.swift', '~> 2.2'
s.dependency 'Socket.swift', '~> 2.3'
end
19 changes: 11 additions & 8 deletions HttpSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,27 +287,28 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1110;
ORGANIZATIONNAME = BiAtoms;
TargetAttributes = {
9DDDF8451F0C14CF00C3D4A6 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1110;
ProvisioningStyle = Automatic;
};
9DDDF84E1F0C14CF00C3D4A6 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1110;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 9DDDF8401F0C14CF00C3D4A6 /* Build configuration list for PBXProject "HttpSwift" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 9DDDF83C1F0C14CF00C3D4A6;
productRefGroup = 9DDDF8471F0C14CF00C3D4A6 /* Products */;
Expand Down Expand Up @@ -425,6 +426,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -490,6 +492,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -562,7 +565,7 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -583,7 +586,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -600,7 +603,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -617,7 +620,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
24 changes: 10 additions & 14 deletions HttpSwift.xcodeproj/xcshareddata/xcschemes/HttpSwift.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1110"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9DDDF8451F0C14CF00C3D4A6"
BuildableName = "HttpSwift.framework"
BlueprintName = "HttpSwift"
ReferencedContainer = "container:HttpSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -39,17 +48,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9DDDF8451F0C14CF00C3D4A6"
BuildableName = "HttpSwift.framework"
BlueprintName = "HttpSwift"
ReferencedContainer = "container:HttpSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -70,8 +68,6 @@
ReferencedContainer = "container:HttpSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ let package = Package(
targets: ["HttpSwift"]),
],
dependencies: [
.package(url: "https://github.com/BiAtoms/Socket.swift.git", from: "2.2.0"),
.package(url: "https://github.com/BiAtoms/Request.swift.git", from: "2.1.0"),
.package(url: "https://github.com/BiAtoms/Socket.swift.git", .upToNextMinor(from: "2.4.0")),
.package(url: "https://github.com/BiAtoms/Request.swift.git", .upToNextMinor(from: "2.3.0")),
],
targets: [
.target(
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To integrate Http.swift into your Xcode project using CocoaPods, specify it in y
```ruby
source 'https://github.com/CocoaPods/Specs.git'
target '<Your Target Name>' do
pod 'Http.swift', '~> 2.1'
pod 'Http.swift', '~> 2.2.0'
end
```

Expand All @@ -72,7 +72,7 @@ $ brew install carthage
To integrate Http.swift into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "BiAtoms/Http.swift" ~> 2.1
github "BiAtoms/Http.swift" ~> 2.2.0
```

Run `carthage update` to build the framework and drag the built `HttpSwift.framework` into your Xcode project.
Expand All @@ -85,7 +85,7 @@ Once you have your Swift package set up, adding Http.swift as a dependency is as

```swift
dependencies: [
.package(url: "https://github.com/BiAtoms/Http.swift.git", from: "2.0.0")
.package(url: "https://github.com/BiAtoms/Http.swift.git", from: "2.2.0")
]
```

Expand Down
10 changes: 5 additions & 5 deletions Sources/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Foundation

public typealias RouteHandler = (Request) throws -> Response
open class Route {
open let method: String
open let path: String
open let paramNames: [String]
open let regexPattern: String
open let handler: RouteHandler
public let method: String
public let path: String
public let paramNames: [String]
public let regexPattern: String
public let handler: RouteHandler
open var middlewares: [MiddlewareHandler] = []

public init(method: String, path: String, handler: @escaping RouteHandler) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SocketSwift

public typealias MiddlewareHandler = (_ request: Request, _ closure: RouteHandler) throws -> Response
open class Server {
open let queue = DispatchQueue(label: "com.biatoms.server-swift." + UUID().uuidString)
public let queue = DispatchQueue(label: "com.biatoms.server-swift." + UUID().uuidString)
open var router = Router()
open var socket: Socket!
open var errorHandler: ErrorHandler.Type = ErrorHandler.self
Expand Down
8 changes: 4 additions & 4 deletions Sources/StaticServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
import Foundation

open class StaticServer {
open static func serveFile(at path: String) throws -> Response {
public static func serveFile(at path: String) throws -> Response {
let file = File(path: path)
if file.exists {
return Response(.ok, body: file.bytes)
}
throw ServerError.httpRouteNotFound
}

open static func serveFile(in directory: String, path: String) throws -> Response {
public static func serveFile(in directory: String, path: String) throws -> Response {
let path = directory.expandingTildeInPath.appendingPathComponent(path)
return try serveFile(at: path)
}

open static func fileBrowser(in directory: String, path subpath: String) throws -> Response {
public static func fileBrowser(in directory: String, path subpath: String) throws -> Response {
let path = directory.expandingTildeInPath.appendingPathComponent(subpath)
if let contents = try? FileManager.default.contentsOfDirectory(atPath: path) {
return renderBrowser(for: subpath, content: contents)
}
return try serveFile(at: path)
}

open static func renderBrowser(for path: String, content: [String]) -> Response {
public static func renderBrowser(for path: String, content: [String]) -> Response {
func wrap(_ tag: String, newLine: Bool = true, attrs: [String: String] = [:], _ content: () -> String) -> String {
return "<\(tag)\(attrs.reduce("") { $0 + " \($1.key)=\"\($1.value)\"" })>\(newLine ? "\n" : "")\(content())</\(tag)>\n"
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/HttpSwiftTests/HttpSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HttpSwiftTests: XCTestCase {
let keyPath = rootPath.appendingPathExtension("key")
let certPath = (path, keyPath, nil as String?)
#else
let path = Bundle(for: HttpSwiftTests.self).url(forResource: "Http.swift", withExtension: "pfx")!
let path = Bundle(for: HttpSwiftTests.self).url(forResource: "Http.swift", withExtension: "pfx") ?? URL(string: NSString(string: URL(string: #file)!.appendingPathComponent("../../Http.swift.pfx").absoluteString).standardizingPath)!
let certPath = (path, "orkhan1234")
#endif
try! server.run(port: 4443, certifiatePath: certPath)
Expand Down

0 comments on commit 440a6dc

Please sign in to comment.