0001 // Cookie.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 public enum CookieError: ErrorType { 0026 case InvalidString
Cookie.swift:138 throw CookieError.InvalidString0027 } 0028 0029 public struct Cookie
Cookie.swift:138 throw CookieError.InvalidString{ 0030 public var name
Cookie.swift:72 extension Cookie: Hashable {Cookie.swift:78 public func ==(lhs: Cookie, rhs: Cookie) -> Bool {Cookie.swift:78 public func ==(lhs: Cookie, rhs: Cookie) -> Bool {Cookie.swift:82 extension Cookie: CustomStringConvertible {Cookie.swift:114 extension Cookie {Cookie.swift:132 public static func parseSetCookie(string: String) throws -> Cookie {Cookie.swift:160 return Cookie(name: name, value: value, attributes: attributes)MessageType.swift:32 public typealias Cookies = Set<Cookie>RequestParser.swift:181 if let cookies = try? Cookie.parseCookie($0.buildingCookieValue) {ResponseParser.swift:137 if let cookie = try? Cookie.parseSetCookie($0.buildingCookieValue) {ResponseParser.swift:176 if let cookie = try? Cookie.parseSetCookie($0.buildingCookieValue) {: String 0031 public var value
Cookie.swift:41 self.name = nameCookie.swift:74 return name.hashValueCookie.swift:79 return lhs.name == rhs.nameCookie.swift:79 return lhs.name == rhs.nameCookie.swift:84 var string = "\(name)=\(value)"Request.swift:221 string += " \(cookie.name)=\(cookie.value)": String 0032 0033 public var expires
Cookie.swift:42 self.value = valueCookie.swift:84 var string = "\(name)=\(value)"Request.swift:221 string += " \(cookie.name)=\(cookie.value)": String? 0034 public var maxAge
Cookie.swift:43 self.expires = expiresCookie.swift:86 if let expires = expires {: Int? 0035 public var domain
Cookie.swift:44 self.maxAge = maxAgeCookie.swift:90 if let maxAge = maxAge {: String? 0036 public var path
Cookie.swift:45 self.domain = domainCookie.swift:94 if let domain = domain {: String? 0037 public var secure
Cookie.swift:46 self.path = pathCookie.swift:98 if let path = path {: Bool 0038 public var HTTPOnly
Cookie.swift:47 self.secure = secureCookie.swift:102 if secure {: Bool 0039 0040 public init
Cookie.swift:48 self.HTTPOnly = HTTPOnlyCookie.swift:106 if HTTPOnly {(name: String, value: String, expires: String? = nil, maxAge: Int? = nil, domain: String? = nil, path: String? = nil, secure: Bool = false, HTTPOnly: Bool = false) { 0041 self.name = name 0042 self.value = value 0043 self.expires = expires 0044 self.maxAge = maxAge 0045 self.domain = domain 0046 self.path = path 0047 self.secure = secure 0048 self.HTTPOnly = HTTPOnly 0049 } 0050 0051 init(name: String, value: String, attributes: [CaseInsensitiveKey: String]) { 0052 let expires = attributes["Path"] 0053 let maxAge = attributes["Max-Age"].flatMap({Int($0)}) 0054 let domain = attributes["Domain"] 0055 let path = attributes["Path"] 0056 let secure = attributes["Secure"] != nil 0057 let HTTPOnly = attributes["HttpOnly"] != nil 0058 0059 self.init( 0060 name: name, 0061 value: value, 0062 domain: domain, 0063 path: path, 0064 expires: expires, 0065 maxAge: maxAge, 0066 secure: secure, 0067 HTTPOnly: HTTPOnly 0068 ) 0069 } 0070 } 0071 0072 extension Cookie: Hashable { 0073 public var hashValue: Int { 0074 return name.hashValue 0075 } 0076 } 0077 0078 public func ==(lhs: Cookie, rhs: Cookie) -> Bool { 0079 return lhs.name == rhs.name 0080 } 0081 0082 extension Cookie: CustomStringConvertible { 0083 public var description
Cookie.swift:59 self.init(: String { 0084 var string = "\(name)=\(value)" 0085 0086 if let expires = expires { 0087 string += "; Expires=\(expires)" 0088 } 0089 0090 if let maxAge = maxAge { 0091 string += "; Max-Age=\(maxAge)" 0092 } 0093 0094 if let domain = domain { 0095 string += "; Domain=\(domain)" 0096 } 0097 0098 if let path = path { 0099 string += "; Path=\(path)" 0100 } 0101 0102 if secure { 0103 string += "; Secure" 0104 } 0105 0106 if HTTPOnly { 0107 string += "; HttpOnly" 0108 } 0109 0110 return string 0111 } 0112 } 0113 0114 extension Cookie { 0115 public static func parseCookie
Response.swift:115 string += "Set-Cookie: \(cookie.description)\n"(string: String) throws -> Cookies { 0116 var cookies = Cookies() 0117 let tokens = string.split(";") 0118 0119 for i in 0 ..< tokens.count { 0120 let cookieTokens = tokens[i].split("=", maxSplit: 1) 0121 0122 if cookieTokens.count != 2 { 0123 throw CookieError.InvalidString 0124 } 0125 0126 cookies.insert(Cookie(name: cookieTokens[0].trim(), value: cookieTokens[1].trim())) 0127 } 0128 0129 return cookies 0130 } 0131 0132 public static func parseSetCookie
RequestParser.swift:181 if let cookies = try? Cookie.parseCookie($0.buildingCookieValue) {(string: String) throws -> Cookie { 0133 let cookieStringTokens = string.split(";") 0134 0135 let cookieTokens = cookieStringTokens[0].split("=") 0136 0137 if cookieTokens.count != 2 { 0138 throw CookieError.InvalidString 0139 } 0140 0141 let name = cookieTokens[0] 0142 let value = cookieTokens[1] 0143 0144 var attributes: [CaseInsensitiveKey: String] = [:] 0145 0146 for i in 1 ..< cookieStringTokens.count { 0147 let attributeTokens = cookieStringTokens[i].split("=") 0148 0149 if attributeTokens.count > 2 { 0150 throw CookieError.InvalidString 0151 } 0152 0153 if attributeTokens.count == 1 { 0154 attributes[CaseInsensitiveKey(attributeTokens[0].trim())] = "" 0155 } else { 0156 attributes[CaseInsensitiveKey(attributeTokens[0].trim())] = attributeTokens[1].trim() 0157 } 0158 } 0159 0160 return Cookie(name: name, value: value, attributes: attributes) 0161 } 0162 }
ResponseParser.swift:137 if let cookie = try? Cookie.parseSetCookie($0.buildingCookieValue) {ResponseParser.swift:176 if let cookie = try? Cookie.parseSetCookie($0.buildingCookieValue) {