Skip to content

Changing the NSHTTPCookie API to match the Darwin version #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Foundation/NSHTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public class NSHTTPCookie : NSObject {
/// - Parameter cookies: The cookies to turn into request headers.
/// - Returns: A dictionary where the keys are header field names, and the values
/// are the corresponding header field values.
public class func requestHeaderFieldsWithCookies(_ cookies: [NSHTTPCookie]) -> [String : String] {
public class func requestHeaderFields(with cookies: [NSHTTPCookie]) -> [String : String] {
var cookieString = cookies.reduce("") { (sum, next) -> String in
return sum + "\(next.cookieRepresentation.name)=\(next.cookieRepresentation.value); "
}
Expand All @@ -336,7 +336,7 @@ public class NSHTTPCookie : NSObject {
/// - Parameter headerFields: The response header fields to check for cookies.
/// - Parameter URL: The URL that the cookies came from - relevant to how the cookies are interpeted.
/// - Returns: An array of NSHTTPCookie objects
public class func cookiesWithResponseHeaderFields(_ headerFields: [String : String], forURL URL: NSURL) -> [NSHTTPCookie] { NSUnimplemented() }
public class func cookies(withResponseHeaderFields headerFields: [String : String], forURL URL: NSURL) -> [NSHTTPCookie] { NSUnimplemented() }

/// Returns a dictionary representation of the receiver.
///
Expand Down Expand Up @@ -380,13 +380,13 @@ public class NSHTTPCookie : NSObject {
/*@NSCopying*/ public var expiresDate: NSDate? {
return self.cookieRepresentation.expiresDate
}

/// Whether the receiver is session-only.
///
/// `true` if this receiver should be discarded at the end of the
/// session (regardless of expiration date), `false` if receiver need not
/// be discarded at the end of the session.
public var sessionOnly: Bool {
public var isSessionOnly: Bool {
return self.cookieRepresentation.sessionOnly
}

Expand All @@ -408,14 +408,14 @@ public class NSHTTPCookie : NSObject {
public var path: String {
return self.cookieRepresentation.path
}

/// Whether the receiver should be sent only over secure channels
///
/// Cookies may be marked secure by a server (or by a javascript).
/// Cookies marked as such must only be sent via an encrypted connection to
/// trusted servers (i.e. via SSL or TLS), and should not be delievered to any
/// javascript applications to prevent cross-site scripting vulnerabilities.
public var secure: Bool {
/// javascript applications to prevent cross-site scripting vulnerabilities.
public var isSecure: Bool {
return self.cookieRepresentation.secure
}

Expand All @@ -426,7 +426,7 @@ public class NSHTTPCookie : NSObject {
/// for URL's that match both the path and domain of the respective Cookies.
/// Specifically these cookies should not be delivered to any javascript
/// applications to prevent cross-site scripting vulnerabilities.
public var HTTPOnly: Bool {
public var isHTTPOnly: Bool {
return self.cookieRepresentation.HTTPOnly
}

Expand Down
10 changes: 5 additions & 5 deletions TestFoundation/TestNSHTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TestNSHTTPCookie: XCTestCase {
])
XCTAssertNil(versionZeroCookieWithInvalidVersionOneProps?.comment)
XCTAssertNil(versionZeroCookieWithInvalidVersionOneProps?.commentURL)
XCTAssert(versionZeroCookieWithInvalidVersionOneProps?.sessionOnly == true)
XCTAssert(versionZeroCookieWithInvalidVersionOneProps?.isSessionOnly == true)

// v0 should never use NSHTTPCookieMaximumAge
XCTAssert(
Expand All @@ -88,13 +88,13 @@ class TestNSHTTPCookie: XCTestCase {
)

XCTAssertNil(versionZeroCookieWithInvalidVersionOneProps?.portList)
XCTAssert(versionZeroCookieWithInvalidVersionOneProps?.secure == true)
XCTAssert(versionZeroCookieWithInvalidVersionOneProps?.isSecure == true)
XCTAssert(versionZeroCookieWithInvalidVersionOneProps?.version == 0)
}

func test_RequestHeaderFields() {
let noCookies: [NSHTTPCookie] = []
XCTAssertEqual(NSHTTPCookie.requestHeaderFieldsWithCookies(noCookies)["Cookie"], "")
XCTAssertEqual(NSHTTPCookie.requestHeaderFields(with: noCookies)["Cookie"], "")

let basicCookies: [NSHTTPCookie] = [
NSHTTPCookie(properties: [
Expand All @@ -111,7 +111,7 @@ class TestNSHTTPCookie: XCTestCase {
])!,
]

let basicCookieString = NSHTTPCookie.requestHeaderFieldsWithCookies(basicCookies)["Cookie"]
let basicCookieString = NSHTTPCookie.requestHeaderFields(with: basicCookies)["Cookie"]
XCTAssertEqual(basicCookieString, "TestCookie1=testValue1; TestCookie2=testValue2")
}
}
}