WOCookie
Inherits from: NSObject
Conforms to: NSObject
(NSObject)
Declared in: WebObjects/WOCookie.h
Class Description
WOCookie is used for the creation and setting of cookies in your response objects. A cookie allows for the persistent storage of client state. Instead of using a WOSession object (which can potentially have a shorter life span), a cookie allows server-side applications to store state in client browsers for a specific or indeterminate amount of time. An advantage to cookies is that the data will be stored on the client and not on the server, allowing the server to maintain less state information. A specific advantage in WebObjects applications is that cookies allow the server to put state into the browser that is not bound to a session. Hence, the client can "leave" your application and return with its cookie's state intact.
A WOCookie object defines a cookie that can be added to the HTTP header for your response. You create a cookie using one of two methods:
To add or remove cookies from the response, use the WOMessage methods addCookie: and removeCookie:. To retrieve cookie data, use the WORequest methods cookieValues, cookieValueForKey:, and cookieValuesForKey:. WORequest returns the data as name/value pairs and not as WOCookie objects, since browsers don't return the additional data WOCookies provide, such as path name and expiration date.
For more information about cookies and their implementation details, see Netscape's preliminary specification at http://www.netscape.com/newsref/std/cookie_spec.html and RFC 2109 - HTTP State Management Mechanism at http://www.cis.ohio-state.edu/htbin/rfc/rfc2109.html.
If and when new details evolve in the implementation of cookies, you can subclass WOCookie and implement new behaviors. Pay particular attention to how you override headerString, which WOResponse uses to fill the HTTP response with a header string.
Method Types
- Creation
- + cookieWithName:value:
- + cookieWithName:value:path:domain:expires:isSecure:
- - initWithName:value:path:domain:expires:isSecure:
- Obtaining a cookie's attributes
- - domain
- - expires
- - headerString
- - isSecure
- - name
- - path
- - value
- Setting a cookie's attributes
- - setDomain:
- - setExpires:
- - setIsSecure:
- - setName:
- - setPath:
- - setValue:
Class Methods
cookieWithName:value:
+ (WOCookie *)cookieWithName:(NSString
*)aName
value:(NSString *)aValue
See Also: - cookieWithName:value:path:domain:expires:isSecure:
cookieWithName:value:path:domain:expires:isSecure:
+ (WOCookie *)cookieWithName:(NSString
*)aName
value:(NSString *)aValue
path:(NSString *)aPath
domain:(NSString *)aDomain
expires:(NSDate *)expirationDate
isSecure:(BOOL)flag
See Also: - cookieWithName:value:, - domain, - expires, - isSecure, - name, - path, - value
Instance Methods
domain
- (NSString *)domain
expires
- (NSDate *)expires
Returns the value of the cookie's "expires" attribute as an NSDate. The expiration date tells the browser how long to keep the cookie in its cache. To have the browser remove the cookie from its cache, set the expiration date to a recent date in the past (see setExpires: for more information).
headerString
- (NSString *)headerString
Returns the string that will be used in the HTTP header. The returned string has the format:
Set-cookie: name=value; expires=date; path=path; domain=domain; secure;The calendar format for the expiration date is:
@"%A, %d-%b-%Y %H:%M:%S GMT"
where all times are converted relative to Greenwich Mean Time.
This method is called by WOResponse when generating the response.
initWithName:value:path:domain:expires:isSecure:
- (id)initWithName:(NSString
*)aName
value:(NSString *)aValue
path:(NSString *)aPath
domain:(NSString *)aDomain
expires:(NSDate *)expirationDate
isSecure:(BOOL)flag
See Also: - domain, - expires, - isSecure, - name, - path, - value
isSecure
- (BOOL)isSecure
name
- (NSString *)name
path
- (NSString *)path
setDomain:
- (void)setDomain:(NSString
*)aDomain
See Also: - cookieWithName:value:path:domain:expires:isSecure:
setExpires:
- (void)setExpires:(NSDate
*)expirationDate
Sets the cookie's "expires" attribute to expirationDate.
If
you want to set the cookie's expiration date to some date in the
distant past-for instance, in order to erase the cookie-don't
use [NSDate distantPast]
. distantPast returns
a date from the year 1 AD, and some browsers incorrectly interpret
this as the year 2001. Instead, set the cooke's expiration date
to an actual date in the recent past.
See Also: - cookieWithName:value:path:domain:expires:isSecure:, - expires
setIsSecure:
- (void)setIsSecure:(BOOL)flag
See Also: - cookieWithName:value:path:domain:expires:isSecure:
setName:
- (void)setName:(NSString
*)aName
See Also: - cookieWithName:value:path:domain:expires:isSecure:, - cookieWithName:value:
setPath:
- (void)setPath:(NSString
*)aPath
See Also: - cookieWithName:value:path:domain:expires:isSecure:
setValue:
- (void)setValue:(NSString
*)aValue
See Also: - cookieWithName:value:path:domain:expires:isSecure:, - cookieWithName:value:
value
- (NSString *)value