Przeglądaj źródła

Fixed compilation errors.

Damian Kołakowski 10 lat temu
rodzic
commit
7d6b2e7cb4

+ 2 - 2
Sources/Swifter/DemoServer.swift

@@ -153,7 +153,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
     }
     
     server["/raw"] = { r in
-        return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { $0.write([UInt8]("test".utf8)) })
+        return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { try? $0.write([UInt8]("test".utf8)) })
     }
     
     server["/redirect"] = { r in
@@ -173,7 +173,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
     server["/stream"] = { r in
         return HttpResponse.raw(200, "OK", nil, { w in
             for i in 0...100 {
-                w.write([UInt8]("[chunk \(i)]".utf8))
+                try? w.write([UInt8]("[chunk \(i)]".utf8))
             }
         })
     }

+ 3 - 3
Sources/Swifter/Files.swift

@@ -16,7 +16,7 @@ public func shareFilesFromDirectory(_ directoryPath: String, defaults: [String]
             for path in defaults {
                 if let file = try? File.openForReading(directoryPath + File.PATH_SEPARATOR + path) {
                     return .raw(200, "OK", [:], { writer in
-                        writer.write(file)
+                        try? writer.write(file)
                         file.close()
                     })
                 }
@@ -24,7 +24,7 @@ public func shareFilesFromDirectory(_ directoryPath: String, defaults: [String]
         }
         if let file = try? File.openForReading(directoryPath + File.PATH_SEPARATOR + fileRelativePath.value) {
             return .raw(200, "OK", [:], { writer in
-                writer.write(file)
+                try? writer.write(file)
                 file.close()
             })
         }
@@ -65,7 +65,7 @@ public func directoryBrowser(_ dir: String) -> ((HttpRequest) -> HttpResponse) {
                     return .notFound
                 }
                 return .raw(200, "OK", [:], { writer in
-                    writer.write(file)
+                    try? writer.write(file)
                     file.close()
                 })
             }

+ 3 - 2
Sources/Swifter/Scopes.swift

@@ -15,8 +15,9 @@ public func scopes(_ scope: Closure) -> ((HttpRequest) -> HttpResponse) {
     return { r in
         ScopesBuffer[Process.tid] = ""
         scope()
-        return .raw(200, "OK", ["Content-Type": "text/html"],
-                    { $0.write([UInt8](("<!DOCTYPE html>"  + (ScopesBuffer[Process.tid] ?? "")).utf8)) })
+        return .raw(200, "OK", ["Content-Type": "text/html"], {
+            try? $0.write([UInt8](("<!DOCTYPE html>"  + (ScopesBuffer[Process.tid] ?? "")).utf8))
+        })
     }
 }