Bug 3603 - nshttpcookie cookiefromproperties + nshttpcookie property values
Summary: nshttpcookie cookiefromproperties + nshttpcookie property values
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-02-22 21:22 UTC by ajb
Modified: 2012-02-29 15:07 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description ajb 2012-02-22 21:22:01 UTC
When creating a new cookie with the code below, goodCookie works, but badCookie fails:

var props = new NSMutableDictionary();
props.Add(new NSString("OriginURL"), new NSString("yodawg.com"));
props.Add(new NSString("Name"), new NSString("iherd"));
props.Add(new NSString("Value"), new NSString("ulikecookies"));

var goodCookie = new NSHttpCookie(props);
var badCookie = NSHttpCookie.CookieFromProperties(props);


Also, can we *PLEASE* get these constants defined so users don't have to guess at the proper property key values:

https://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSHTTPCookie_Class/Reference/Reference.html#//apple_ref/doc/uid/20001702-DontLinkElementID_2
Comment 2 Sebastien Pouliot 2012-02-23 08:12:23 UTC
Both your cookies are bad. Objective-C selectors for them both returns null. However when we map a selector to a .NET constructor we can't return null - so an empty instance is returned (i.e. it's handle is 0x0).

This code will work:

			var props = new NSMutableDictionary ();
			props.Add (NSHttpCookie.KeyOriginURL, new NSString("http://yodawg.com"));
			props.Add (NSHttpCookie.KeyName, new NSString("iherd"));
			props.Add (NSHttpCookie.KeyValue, new NSString("ulikecookies"));
			props.Add (NSHttpCookie.KeyPath, new NSString("/"));

The differences are:
* it provides an URL scheme, http://, to the origin URL;
* it provides a Path (mandatory);
* it uses the (already defined) constants (but it would work with manually created keys)

It still a pretty ugly API to use (outside Objective-C ;-) so I'll add a some .NET constructors, that will help people write beautiful code, before closing the bug report.
Comment 3 Sebastien Pouliot 2012-02-23 11:25:16 UTC
maccore
master 7412f7ae48967b396918502c3bf273c592e40f9d
5.2-series b5e8d21f68909cfeb6c54a65092cd3bc17cf80f4

monotouch
master 1085aac6faeff1674e01fbcb6fc2b3c7514b0d4d
5.2-series ebb19e36645e75f85cd9382c10076733f7d35824
Comment 4 Eric Beisecker 2012-02-29 15:07:43 UTC
Verified new Constructor exists and creates cookie with data provided.