Skip to content

[HTTPCookie] Make cookies(withResponseHeaderFields:for:) signature match Darwin #858

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
Feb 1, 2017
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
4 changes: 2 additions & 2 deletions Foundation/NSHTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ open class HTTPCookie : 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
open class func cookies(withResponseHeaderFields headerFields: [String : String], forURL url: URL) -> [HTTPCookie] {
open class func cookies(withResponseHeaderFields headerFields: [String : String], for URL: URL) -> [HTTPCookie] {

//HTTP Cookie parsing based on RFC 6265: https://tools.ietf.org/html/rfc6265
//Though RFC6265 suggests that multiple cookies cannot be folded into a single Set-Cookie field, this is
Expand All @@ -405,7 +405,7 @@ open class HTTPCookie : NSObject {
//bake the cookies
var httpCookies: [HTTPCookie] = []
for i in 0..<cookieIndices.count-1 {
if let aCookie = createHttpCookie(url: url, pairs: nameValuePairs[cookieIndices[i]..<cookieIndices[i+1]]) {
if let aCookie = createHttpCookie(url: URL, pairs: nameValuePairs[cookieIndices[i]..<cookieIndices[i+1]]) {
httpCookies.append(aCookie)
}
}
Expand Down
10 changes: 5 additions & 5 deletions TestFoundation/TestNSHTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ class TestNSHTTPCookie: XCTestCase {
"Set-Cookie": "fr=anjd&232; Max-Age=7776000; path=/; domain=.example.com; secure; httponly",
"header2":"value2",
"header3":"value3"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, forURL: URL(string: "http://example.com")!)
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, for: URL(string: "http://example.com")!)
XCTAssertEqual(cookies.count, 1)
XCTAssertEqual(cookies[0].name, "fr")
XCTAssertEqual(cookies[0].value, "anjd&232")
}

func test_cookiesWithResponseHeader0cookies() {
let header = ["header1":"value1", "header2":"value2", "header3":"value3"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, forURL: URL(string: "http://example.com")!)
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, for: URL(string: "http://example.com")!)
XCTAssertEqual(cookies.count, 0)
}

Expand All @@ -142,7 +142,7 @@ class TestNSHTTPCookie: XCTestCase {
"Set-Cookie": "fr=a&2@#; Max-Age=1186000; path=/; domain=.example.com; secure, xd=plm!@#;path=/;domain=.example2.com",
"header2":"value2",
"header3":"value3"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, forURL: URL(string: "http://example.com")!)
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, for: URL(string: "http://example.com")!)
XCTAssertEqual(cookies.count, 2)
XCTAssertTrue(cookies[0].isSecure)
XCTAssertFalse(cookies[1].isSecure)
Expand All @@ -153,7 +153,7 @@ class TestNSHTTPCookie: XCTestCase {
"Set-Cookie": "fr=anjd&232; expires=Wed, 21 Sep 2016 05:33:00 GMT; Max-Age=7776000; path=/; secure; httponly",
"header2":"value2",
"header3":"value3"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, forURL: URL(string: "http://example.com")!)
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, for: URL(string: "http://example.com")!)
XCTAssertEqual(cookies[0].domain, "http://example.com")
XCTAssertNotNil(cookies[0].expiresDate)

Expand All @@ -173,7 +173,7 @@ class TestNSHTTPCookie: XCTestCase {
"Set-Cookie": "fr=tx; expires=Wed, 21-Sep-2016 05:33:00 GMT; Max-Age=7776000; secure; httponly",
"header2":"value2",
"header3":"value3"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, forURL: URL(string: "http://example.com")!)
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, for: URL(string: "http://example.com")!)
XCTAssertEqual(cookies[0].domain, "http://example.com")
XCTAssertEqual(cookies[0].path, "/")
}
Expand Down