#1068 Cookie handling broken - only sends one cookie

v1.5.0.10
closed
Dare Obasanjo
5
2012-09-23
2007-05-12
Dare Obasanjo
No

Hi team,

Something about the cookie handler isn't working right. RSS Bandit only sends the first cookie name/value pair for a domain when requesting a feed update.

ex: IE sends this cookie when requesting a page on my domain:
a=1; b=2; c=3; test=a

RSS bandit sends this cookie:
a=1

Suggestions? Looking in CurrentWork\Source\NewsComponents\Net\AsyncWebRequest.cs(1403), clearly there's a bug in there somewhere. I'll be happy to try to fix it rather than wait for the next release. :)

Does this project build with VC# 2005? On import it said the project was built with a prior version.

Change this function AsyncWebRequest.cs:GetCookieContainerUri to this:

    private static CookieContainer GetCookieContainerUri(Uri url) {
        CookieContainer container = new CookieContainer();
        string cookieHeaders = RetrieveIECookiesForUrl(url.AbsoluteUri);
        if (cookieHeaders.Length > 0) {
            try{
                // This doesn't work for ';' separated cookies!!!
        //container.SetCookies(url, cookieHeaders);
                // example: a=2; b=3; c=4; d=5; e=YES
                string cookieHeaders2 = cookieHeaders.Replace(';', ',');
                container.SetCookies(url, cookieHeaders2);
            }catch(System.Net.CookieException ce){ //we might get an error on malformed cookies
                _log.Error("GetCookieContainerUri() caused exception", ce);
            }
        }
        return container;
    }

The blind swap of a semicolon in the raw cookie string to the expected comma separator of the CookieContainer set method may cause other problems if your cookies expect to store semicolons. Though it works for my purposes.

Discussion

  • Logged In: YES
    user_id=714452
    Originator: NO

    We also get exceptions on Vista/CLR 2.0 like this:
    System.Net.CookieException: An error occurred when parsing the Cookie header for Uri 'http://weblogs.asp.net/favicon.ico'. ---> System.Net.CookieException: Cookie format error.
    at System.Net.CookieContainer.CookieCutter(Uri uri, String headerName, String setCookieHeader, Boolean isThrow)
    --- End of inner exception stack trace ---
    at System.Net.CookieContainer.CookieCutter(Uri uri, String headerName, String setCookieHeader, Boolean isThrow)
    at System.Net.CookieContainer.SetCookies(Uri uri, String cookieHeader)
    at NewsComponents.Net.HttpCookieManager.GetCookieContainerUri(Uri url)

     
  • James Harrell
    James Harrell
    2008-03-07

    Logged In: YES
    user_id=339843
    Originator: NO

    I reported this bug and provided the code to fix it quite a while back. Can you implement this code in the next release?