Only the HTTP connection server should set cookies. It does this with the Set-Cookie field in the headers.
The cookie store that you linked to processes all NSURLConnection cookie actions (both receiving and setting), and in general - you should not modify cookies yourself. If you want to override, you cannot use NSURLConnection and you will need to use CFReadStreamRef and handle the connection and manually create CFHTTPMessageRef.
You will need to process cookies if you are implementing server-side HTTP communications.
If you are using the CFHTTPMessageRef server, then:
NSDate *expiryDate =
CFHTTPMessageSetHeaderFieldValue(
response,
(CFStringRef)@"Set-Cookie",
(CFStringRef)[NSString stringWithFormat:
@"SomeCookieName=%@;Path=/;expires=%@",
someStringValue,
[dateFormat stringFromDate:expiryDate]]);
where responseis the one CFHTTPMessageRefyou use to answer. You can use CFHTTPMessageCopyAllHeaderFieldsand get the object for the cookie key to retrieve cookies from the client in the CFHTTPMessageRef header.
source
share