Skip to content

Commit addc5d2

Browse files
committed
Merge branch 'pr/34'
2 parents 0faf01e + 5cb8bce commit addc5d2

File tree

1 file changed

+65
-24
lines changed

1 file changed

+65
-24
lines changed

Foundation/NSHTTPCookie.swift

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,79 +11,79 @@
1111
@const NSHTTPCookieName
1212
@discussion Key for cookie name
1313
*/
14-
public let NSHTTPCookieName: String = "" // NSUnimplemented
14+
public let NSHTTPCookieName: String = "Name"
1515

1616
/*!
1717
@const NSHTTPCookieValue
1818
@discussion Key for cookie value
1919
*/
20-
public let NSHTTPCookieValue: String = "" // NSUnimplemented
20+
public let NSHTTPCookieValue: String = "Value"
2121

2222
/*!
2323
@const NSHTTPCookieOriginURL
2424
@discussion Key for cookie origin URL
2525
*/
26-
public let NSHTTPCookieOriginURL: String = "" // NSUnimplemented
26+
public let NSHTTPCookieOriginURL: String = "OriginURL"
2727

2828
/*!
2929
@const NSHTTPCookieVersion
3030
@discussion Key for cookie version
3131
*/
32-
public let NSHTTPCookieVersion: String = "" // NSUnimplemented
32+
public let NSHTTPCookieVersion: String = "Version"
3333

3434
/*!
3535
@const NSHTTPCookieDomain
3636
@discussion Key for cookie domain
3737
*/
38-
public let NSHTTPCookieDomain: String = "" // NSUnimplemented
38+
public let NSHTTPCookieDomain: String = "Domain"
3939

4040
/*!
4141
@const NSHTTPCookiePath
4242
@discussion Key for cookie path
4343
*/
44-
public let NSHTTPCookiePath: String = "" // NSUnimplemented
44+
public let NSHTTPCookiePath: String = "Path"
4545

4646
/*!
4747
@const NSHTTPCookieSecure
4848
@discussion Key for cookie secure flag
4949
*/
50-
public let NSHTTPCookieSecure: String = "" // NSUnimplemented
50+
public let NSHTTPCookieSecure: String = "Secure"
5151

5252
/*!
5353
@const NSHTTPCookieExpires
5454
@discussion Key for cookie expiration date
5555
*/
56-
public let NSHTTPCookieExpires: String = "" // NSUnimplemented
56+
public let NSHTTPCookieExpires: String = "Expires"
5757

5858
/*!
5959
@const NSHTTPCookieComment
6060
@discussion Key for cookie comment text
6161
*/
62-
public let NSHTTPCookieComment: String = "" // NSUnimplemented
62+
public let NSHTTPCookieComment: String = "Comment"
6363

6464
/*!
6565
@const NSHTTPCookieCommentURL
6666
@discussion Key for cookie comment URL
6767
*/
68-
public let NSHTTPCookieCommentURL: String = "" // NSUnimplemented
68+
public let NSHTTPCookieCommentURL: String = "CommentURL"
6969

7070
/*!
7171
@const NSHTTPCookieDiscard
7272
@discussion Key for cookie discard (session-only) flag
7373
*/
74-
public let NSHTTPCookieDiscard: String = "" // NSUnimplemented
74+
public let NSHTTPCookieDiscard: String = "Discard"
7575

7676
/*!
7777
@const NSHTTPCookieMaximumAge
7878
@discussion Key for cookie maximum age (an alternate way of specifying the expiration)
7979
*/
80-
public let NSHTTPCookieMaximumAge: String = "" // NSUnimplemented
80+
public let NSHTTPCookieMaximumAge: String = "Max-Age"
8181

8282
/*!
8383
@const NSHTTPCookiePort
8484
@discussion Key for cookie ports
8585
*/
86-
public let NSHTTPCookiePort: String = "" // NSUnimplemented
86+
public let NSHTTPCookiePort: String = "Port"
8787

8888

8989
/*!
@@ -95,6 +95,7 @@ public let NSHTTPCookiePort: String = "" // NSUnimplemented
9595
attributes of a cookie.
9696
*/
9797
public class NSHTTPCookie : NSObject {
98+
var _properties: [String : AnyObject]
9899

99100
/*!
100101
@method initWithProperties:
@@ -219,7 +220,21 @@ public class NSHTTPCookie : NSObject {
219220
dictionary keys is invalid, for example because a required key is
220221
missing, or a recognized key maps to an illegal value.
221222
*/
222-
public init?(properties: [String : AnyObject]) { NSUnimplemented() }
223+
public init?(properties: [String : AnyObject]) {
224+
func isValidProperty(property: String?) -> Bool {
225+
if let propertyValue = property {
226+
return propertyValue.length > 0 && (propertyValue as NSString).rangeOfString("/n").location == NSNotFound
227+
}
228+
return false
229+
}
230+
if !isValidProperty(properties[NSHTTPCookiePath] as? String)
231+
|| !isValidProperty(properties[NSHTTPCookieDomain] as? String)
232+
|| !isValidProperty(properties[NSHTTPCookieName] as? String)
233+
|| !isValidProperty(properties[NSHTTPCookieValue] as? String) {
234+
return nil
235+
}
236+
_properties = properties
237+
}
223238

224239
/*!
225240
@method cookieWithProperties:
@@ -268,7 +283,9 @@ public class NSHTTPCookie : NSObject {
268283
for descriptions of the supported keys and values.
269284
@result The dictionary representation of the receiver.
270285
*/
271-
public var properties: [String : AnyObject]? { NSUnimplemented() }
286+
public var properties: [String : AnyObject]? {
287+
return _properties
288+
}
272289

273290
/*!
274291
@method version
@@ -277,21 +294,27 @@ public class NSHTTPCookie : NSObject {
277294
Version 1 maps to RFC2965 cookies. There may be future versions.
278295
@result the version of the receiver.
279296
*/
280-
public var version: Int { NSUnimplemented() }
297+
public var version: Int {
298+
return (_properties[NSHTTPCookieVersion] as! Int)
299+
}
281300

282301
/*!
283302
@method name
284303
@abstract Returns the name of the receiver.
285304
@result the name of the receiver.
286305
*/
287-
public var name: String { NSUnimplemented() }
306+
public var name: String {
307+
return (_properties[NSHTTPCookieName] as! NSString)._swiftObject
308+
}
288309

289310
/*!
290311
@method value
291312
@abstract Returns the value of the receiver.
292313
@result the value of the receiver.
293314
*/
294-
public var value: String { NSUnimplemented() }
315+
public var value: String {
316+
return (_properties[NSHTTPCookieValue] as! NSString)._swiftObject
317+
}
295318

296319
/*!
297320
@method expiresDate
@@ -302,7 +325,12 @@ public class NSHTTPCookie : NSObject {
302325
date. This will be the case only for "session-only" cookies.
303326
@result The expires date of the receiver.
304327
*/
305-
/*@NSCopying*/ public var expiresDate: NSDate? { NSUnimplemented() }
328+
/*@NSCopying*/ public var expiresDate: NSDate? {
329+
if let expiresDate = _properties[NSHTTPCookieExpires] as? NSDate {
330+
return expiresDate
331+
}
332+
return nil
333+
}
306334

307335
/*!
308336
@method isSessionOnly
@@ -311,7 +339,9 @@ public class NSHTTPCookie : NSObject {
311339
session (regardless of expiration date), NO if receiver need not
312340
be discarded at the end of the session.
313341
*/
314-
public var sessionOnly: Bool { NSUnimplemented() }
342+
public var sessionOnly: Bool {
343+
return !(_properties[NSHTTPCookieExpires] is NSDate)
344+
}
315345

316346
/*!
317347
@method domain
@@ -322,7 +352,9 @@ public class NSHTTPCookie : NSObject {
322352
restrictions are valid. See RFC 2965 for more detail.
323353
@result The domain of the receiver.
324354
*/
325-
public var domain: String { NSUnimplemented() }
355+
public var domain: String {
356+
return (_properties[NSHTTPCookieDomain] as! NSString)._swiftObject
357+
}
326358

327359
/*!
328360
@method path
@@ -332,7 +364,9 @@ public class NSHTTPCookie : NSObject {
332364
be sent for children of that path, so "/" is the most general.
333365
@result The path of the receiver.
334366
*/
335-
public var path: String { NSUnimplemented() }
367+
public var path: String {
368+
return (_properties[NSHTTPCookiePath] as! NSString)._swiftObject
369+
}
336370

337371
/*!
338372
@method isSecure
@@ -370,7 +404,9 @@ public class NSHTTPCookie : NSObject {
370404
@result The comment of the receiver, or nil if the receiver has no
371405
comment.
372406
*/
373-
public var comment: String? { NSUnimplemented() }
407+
public var comment: String? {
408+
return (_properties[NSHTTPCookieComment] as! NSString)._swiftObject
409+
}
374410

375411
/*!
376412
@method commentURL
@@ -381,7 +417,12 @@ public class NSHTTPCookie : NSObject {
381417
@result The comment URL of the receiver, or nil if the receiver
382418
has no comment URL.
383419
*/
384-
/*@NSCopying*/ public var commentURL: NSURL? { NSUnimplemented() }
420+
/*@NSCopying*/ public var commentURL: NSURL? {
421+
if let commentURL = _properties[NSHTTPCookieCommentURL] as? NSURL {
422+
return commentURL
423+
}
424+
return nil
425+
}
385426

386427
/*!
387428
@method portList

0 commit comments

Comments
 (0)