Parcourir la source

added default value for custom headers

Yuri Goncharov il y a 4 ans
Parent
commit
685855f6cd

+ 1 - 1
Xcode/Sources/HttpResponse.swift

@@ -80,7 +80,7 @@ public enum HttpResponseBody {
 public enum HttpResponse {
 
     case switchProtocols([String: String], (Socket) -> Void)
-    case ok(HttpResponseBody, [String: String]), created, accepted
+    case ok(HttpResponseBody, [String: String] = [:]), created, accepted
     case movedPermanently(String)
     case movedTemporarily(String)
     case badRequest(HttpResponseBody?), unauthorized, forbidden, notFound, notAcceptable

+ 1 - 1
Xcode/Tests/PingServer.swift

@@ -17,7 +17,7 @@ extension HttpServer {
     class func pingServer() -> HttpServer {
         let server = HttpServer()
         server.GET["/ping"] = { request in
-            return HttpResponse.ok(.text("pong!"), [:])
+            return HttpResponse.ok(.text("pong!"))
         }
         return server
     }

+ 2 - 2
Xcode/Tests/ServerThreadingTests.swift

@@ -35,7 +35,7 @@ class ServerThreadingTests: XCTestCase {
         let queue = DispatchQueue(label: "com.swifter.threading")
         let hostURL: URL
 
-        server.GET[path] = { .ok(.htmlBody("You asked for " + $0.path), [:]) }
+        server.GET[path] = { .ok(.htmlBody("You asked for " + $0.path)) }
 
         do {
 
@@ -73,7 +73,7 @@ class ServerThreadingTests: XCTestCase {
     func testShouldHandleTheSameRequestConcurrently() {
 
         let path = "/a/:b/c"
-        server.GET[path] = { .ok(.htmlBody("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")
 

+ 9 - 9
Xcode/Tests/SwifterTestsHttpRouter.swift

@@ -26,7 +26,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterSlashRoot() {
 
         router.register(nil, path: "/", handler: { _ in
-            return .ok(.htmlBody("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(.htmlBody("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(.htmlBody("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(.htmlBody("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(.htmlBody("OK"), [:])
+            return .ok(.htmlBody("OK"))
         })
 
         XCTAssertNil(router.route(nil, path: "/"))
@@ -88,7 +88,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterMultiplePathSegmentWildcardTail() {
 
         router.register(nil, path: "/a/b/**", handler: { _ in
-            return .ok(.htmlBody("OK"), [:])
+            return .ok(.htmlBody("OK"))
         })
 
         XCTAssertNil(router.route(nil, path: "/"))
@@ -100,11 +100,11 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterEmptyTail() {
 
         router.register(nil, path: "/a/b/", handler: { _ in
-            return .ok(.htmlBody("OK"), [:])
+            return .ok(.htmlBody("OK"))
         })
 
         router.register(nil, path: "/a/b/:var", handler: { _ in
-            return .ok(.htmlBody("OK"), [:])
+            return .ok(.htmlBody("OK"))
         })
 
         XCTAssertNil(router.route(nil, path: "/"))
@@ -120,7 +120,7 @@ class SwifterTestsHttpRouter: XCTestCase {
     func testHttpRouterPercentEncodedPathSegments() {
 
         router.register(nil, path: "/a/<>/^", handler: { _ in
-            return .ok(.htmlBody("OK"), [:])
+            return .ok(.htmlBody("OK"))
         })
 
         XCTAssertNil(router.route(nil, path: "/"))