diff --git a/Sources/Swifter/DemoServer.swift b/Sources/Swifter/DemoServer.swift index cad48913..a67e43f9 100644 --- a/Sources/Swifter/DemoServer.swift +++ b/Sources/Swifter/DemoServer.swift @@ -48,7 +48,8 @@ public func demoServer(publicDir: String?) -> HttpServer { } server["/json"] = { request in - return .OK(.Json(["posts": [["id": 1, "message": "hello world"], ["id": 2, "message": "sample message"]], "new_updates": false])) + let jsonObject: NSDictionary = [NSString(string: "foo"): NSNumber(int: 3), NSString(string: "bar"): NSString(string: "baz")] + return .OK(.Json(jsonObject)) } server["/redirect"] = { request in diff --git a/Sources/Swifter/HttpHandlers.swift b/Sources/Swifter/HttpHandlers.swift index 9ff8957b..46a0c92c 100644 --- a/Sources/Swifter/HttpHandlers.swift +++ b/Sources/Swifter/HttpHandlers.swift @@ -10,8 +10,6 @@ public class HttpHandlers { private static let rangeExpression = try! NSRegularExpression(pattern: "bytes=(\\d*)-(\\d*)", options: .CaseInsensitive) - private static let cache = NSCache() - public class func directory(dir: String) -> (HttpRequest -> HttpResponse) { return { request in @@ -21,16 +19,10 @@ public class HttpHandlers { let filesPath = dir + "/" + localPath.1 - let cachedBody = cache.objectForKey(filesPath) as? NSData - - guard let fileBody = cachedBody ?? NSData(contentsOfFile: filesPath) else { + guard let fileBody = NSData(contentsOfFile: filesPath) else { return HttpResponse.NotFound } - if cachedBody == nil { - cache.setObject(fileBody, forKey: filesPath) - } - if let rangeHeader = request.headers["range"] { guard let match = rangeExpression.matchesInString(rangeHeader, options: .Anchored, range: NSRange(location: 0, length: rangeHeader.characters.count)).first where match.numberOfRanges == 3 else { diff --git a/Sources/Swifter/HttpRouter.swift b/Sources/Swifter/HttpRouter.swift index 8558a131..635c2006 100644 --- a/Sources/Swifter/HttpRouter.swift +++ b/Sources/Swifter/HttpRouter.swift @@ -50,7 +50,11 @@ public class HttpRouter { } } if patternToken.characters.first == ":" { +#if os(Linux) + params[patternToken.substringFromIndex(1)] = valueToken +#else params[patternToken.substringFromIndex(patternToken.characters.startIndex.successor())] = valueToken +#endif } else { if patternToken != valueToken { return nil