Преглед изворни кода

Fixes tests using the new htmlBody response type

Christian Steffens пре 7 година
родитељ
комит
896b4a405b

+ 1 - 1
README.md

@@ -19,7 +19,7 @@ Tiny http server engine written in [Swift](https://developer.apple.com/swift/) p
 ### How to start?
 ```swift
 let server = HttpServer()
-server["/hello"] = { .ok(.html("You asked for \($0)"))  }
+server["/hello"] = { .ok(.htmlBody("You asked for \($0)"))  }
 server.start()
 ```
 

+ 5 - 5
XCode/Sources/DemoServer.swift

@@ -30,7 +30,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
         }
     }
     
-    server["/magic"] = { .ok(.html("You asked for " + $0.path)) }
+    server["/magic"] = { .ok(.htmlBody("You asked for " + $0.path)) }
     
     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(.html(response))
+        return HttpResponse.ok(.htmlBody(response))
     }
     
     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(.html(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
+        return HttpResponse.ok(.htmlBody(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
     }
     
     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(.html(longResponse))
+        return .ok(.htmlBody(longResponse))
     }
     
     server["/wildcard/*/test/*/:param"] = { request in
-        return .ok(.html(request.path))
+        return .ok(.htmlBody(request.path))
     }
     
     server["/stream"] = { _ in

+ 1 - 1
XCode/SwifterSampleOSX/main.swift

@@ -10,7 +10,7 @@ import Swifter
 do {
     let server = demoServer(try String.File.currentWorkingDirectory())
     server["/testAfterBaseRoute"] = { request in
-        return .ok(.html("ok !"))
+        return .ok(.htmlBody("ok !"))
     }
     
     if #available(OSXApplicationExtension 10.10, *) {

+ 2 - 2
XCode/Tests/ServerThreadingTests.swift

@@ -32,7 +32,7 @@ class ServerThreadingTests: XCTestCase {
         let queue = DispatchQueue(label: "com.swifter.threading")
         let hostURL: URL
         
-        server.GET[path] = { .ok(.html("You asked for " + $0.path)) }
+        server.GET[path] = { .ok(.htmlBody("You asked for " + $0.path)) }
         
         do {
             
@@ -70,7 +70,7 @@ class ServerThreadingTests: XCTestCase {
     func testShouldHandleTheSameRequestConcurrently() {
         
         let path = "/a/:b/c"
-        server.GET[path] = { .ok(.html("You asked for " + $0.path)) }
+        server.GET[path] = { .ok(.htmlBody("You asked for " + $0.path)) }
         
         var requestExpectation: XCTestExpectation? = expectation(description: "Should handle the request concurrently")
         

+ 8 - 8
XCode/Tests/SwifterTestsHttpRouter.swift

@@ -26,7 +26,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterSlashRoot() {
         
         router.register(nil, path: "/", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNotNil(router.route(nil, path: "/"))
@@ -35,7 +35,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterSimplePathSegments() {
         
         router.register(nil, path: "/a/b/c/d", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNil(router.route(nil, path: "/"))
@@ -48,7 +48,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterSinglePathSegmentWildcard() {
         
         router.register(nil, path: "/a/*/c/d", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNil(router.route(nil, path: "/"))
@@ -62,7 +62,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterVariables() {
         
         router.register(nil, path: "/a/:arg1/:arg2/b/c/d/:arg3", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNil(router.route(nil, path: "/"))
@@ -76,7 +76,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterMultiplePathSegmentWildcards() {
         
         router.register(nil, path: "/a/**/e/f/g", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNil(router.route(nil, path: "/"))
@@ -88,11 +88,11 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterEmptyTail() {
         
         router.register(nil, path: "/a/b/", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         router.register(nil, path: "/a/b/:var", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNil(router.route(nil, path: "/"))
@@ -108,7 +108,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterPercentEncodedPathSegments() {
         
         router.register(nil, path: "/a/<>/^", handler: { _ in
-            return .ok(.html("OK"))
+            return .ok(.htmlBody("OK"))
         })
         
         XCTAssertNil(router.route(nil, path: "/"))