         })
     }
 
+    func testCookieFromServer() {
+        performServerTest(router, asyncTasks: {
+            self.performRequest("get", path: "/1/sendcookie", callback: {response in
+                XCTAssertEqual(response!.statusCode, HttpStatusCode.OK, "/1/sendcookie route did not match single path request")
+
+                let (cookie1, cookie1Expire) = self.cookieFromResponse(response!, named: cookie1Name)
+                XCTAssert(cookie1 != nil, "Cookie \(cookie1Name) wasn't found in the response.")
+                XCTAssertEqual(cookie1!.value, cookie1Value, "Value of Cookie \(cookie1Name) is not \(cookie1Value), was \(cookie1!.value)")
+                XCTAssertEqual(cookie1!.path, "/", "Path of Cookie \(cookie1Name) is not (/), was \(cookie1!.path)")
+                XCTAssertEqual(cookie1!.domain, cookieHost, "Domain of Cookie \(cookie1Name) is not \(cookieHost), was \(cookie1!.domain)")
+                XCTAssertFalse(cookie1!.secure, "\(cookie1Name) was marked as secure. Should have not been marked so.")
+                XCTAssertNil(cookie1Expire, "\(cookie1Name) had an expiration date. It shouldn't have had one")
+
+                let (cookie2, cookie2Expire) = self.cookieFromResponse(response!, named: cookie2Name)
+                XCTAssert(cookie2 != nil, "Cookie \(cookie2Name) wasn't found in the response.")
+                XCTAssertEqual(cookie2!.value, cookie2Value, "Value of Cookie \(cookie2Name) is not \(cookie2Value), was \(cookie2!.value)")
+                XCTAssertEqual(cookie2!.path, "/", "Path of Cookie \(cookie2Name) is not (/), was \(cookie2!.path)")
+                XCTAssertEqual(cookie2!.domain, cookieHost, "Domain of Cookie \(cookie2Name) is not \(cookieHost), was \(cookie2!.domain)")
+                XCTAssertFalse(cookie2!.secure, "\(cookie2Name) was marked as secure. Should have not been marked so.")
+                XCTAssertNotNil(cookie2Expire, "\(cookie2Name) had no expiration date. It should have had one")
+                XCTAssertEqual(cookie2Expire!, SpiUtils.httpDate(cookie2ExpireExpected))
+            })
+        },
+        {
+            self.performRequest("get", path: "/2/sendcookie", callback: {response in
+                XCTAssertEqual(response!.statusCode, HttpStatusCode.OK, "/2/sendcookie route did not match single path request")
+
+                let (cookie, cookieExpire) = self.cookieFromResponse(response!, named: cookie3Name)
+                XCTAssertNotNil(cookie, "Cookie \(cookie3Name) wasn't found in the response.")
+                XCTAssertEqual(cookie!.value, cookie3Value, "Value of Cookie \(cookie3Name) is not \(cookie3Value), was \(cookie!.value)")
+                XCTAssertEqual(cookie!.path, "/", "Path of Cookie \(cookie3Name) is not (/), was \(cookie!.path)")
+                XCTAssertEqual(cookie!.domain, cookieHost, "Domain of Cookie \(cookie3Name) is not \(cookieHost), was \(cookie!.domain)")
+                XCTAssertTrue(cookie!.secure, "\(cookie3Name) wasn't marked as secure. It should have been marked so.")
+                XCTAssertNil(cookieExpire, "\(cookie3Name) had an expiration date. It shouldn't have had one")
+            })
+        })
+    }
+
+    func cookieFromResponse(response: ClientResponse, named: String) -> (NSHTTPCookie?, String?) {
+        var resultCookie: NSHTTPCookie? = nil
+        var resultExpire: String?
+        for (headerKey, headerValues) in response.headersAsArrays  {
+            if  headerKey.bridge().lowercaseString  ==  "set-cookie"  {
+                for headerValue in headerValues {
+                    let parts = headerValue.bridge().componentsSeparatedByString("; ")
+                    let nameValue = parts[0].bridge().componentsSeparatedByString("=")
+                    XCTAssertEqual(nameValue.count, 2, "Malformed Set-Cookie header \(headerValue)")
+
+                    if  nameValue[0] == named  {
+                        var properties = [NSHTTPCookieName: nameValue[0], NSHTTPCookieValue: nameValue[1]]
+
+                        for  part in parts[1..<parts.count] {
+                            var pieces = part.bridge().componentsSeparatedByString("=")
+                            switch(pieces[0].bridge().lowercaseString) {
+                                case "secure", "httponly":
+                                    properties[NSHTTPCookieSecure] = "Yes"
+                                case "path" where pieces.count == 2:
+                                    properties[NSHTTPCookiePath] = pieces[1]
+                                case "domain" where pieces.count == 2:
+                                    properties[NSHTTPCookieDomain] = pieces[1]
+                                case "expires" where pieces.count == 2:
+                                    resultExpire = pieces[1]
+                                default:
+                                    XCTFail("Malformed Set-Cookie header \(headerValue)")
+                            }
+                        }
+
+                        XCTAssertNotNil(properties[NSHTTPCookieDomain], "Malformed Set-Cookie header \(headerValue)")
+                        resultCookie = NSHTTPCookie(properties: properties)
+                        break
+                    }
+                }
+            }
+        }
+
+        return (resultCookie, resultExpire)
+    }
+
+
     static func setupRouter() -> Router {
         let router = Router()
 

            next()
        }

        return router
    }
}

@testable import Kitura
@testable import KituraNet

let cookie1Name = "KituraTest1"
let cookie1Value = "Testing-Testing-1-2-3"
let cookie2Name = "KituraTest2"
let cookie2Value = "Testing-Testing"
let cookie2ExpireExpected = NSDate(timeIntervalSinceNow: 600.0)
let cookie3Name = "KituraTest3"
let cookie3Value = "A-testing-we-go"

let cookieHost = "localhost"

class TestCookies : KituraTest {
    #if os(Linux)
        override var allTests : [(String, () throws -> Void)] {
            return [
                ("testCookieToServer", testCookieToServer),
                ("testCookieFromServer", testCookieFromServer)
            ]
        }
    #endif
