How to get Cookie value with GetTokenValue()

4 posts, 0 answers
  1. Taka
    Taka avatar
    4 posts
    Member since:
    May 2015

    Posted 26 Dec 2015 Link to this post

    Hi,

     

    I try to get cookie values in request header with GetTokenValue(), but failing.

     

    Script:

    var result1 = oSession.RequestHeaders.GetTokenValue("Cookie",  "target");

    var result2 = oSession.RequestHeaders.GetTokenValue("Cookie",  "TEST_target");

     

    [Request Header A] Cookie: target=X; TEST_target=Y

    --> resut1 = X, result2=Y

     

    [Request Header B] Cookie: Test_target=Y; target=X

    --> resut1 = Y, result2=Y

     

    Is this in the specifications? Please give me some advice.

  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 28 Dec 2015 Link to this post

    Hello, Taka--

    GetTokenValue isn't really intended for parsing cookie headers, although it will work for most simple header values.

    think you're saying that in this case a single request has two cookie headers? If so, the problem is that the GetTokenValue call is only looking at the first one of them.

    If that's not what you're saying, please provide the full sets of headers for each attempt that you're trying.

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Taka
    Taka avatar
    4 posts
    Member since:
    May 2015

    Posted 29 Dec 2015 in reply to Eric Lawrence Link to this post

    Hello Eric,

    Thank you for your advice.
    This result appears both in single Cookie header and multi-Cookie headers. The GetTokenValue() function seems to return a first Cookie value including a specified string as Cookie name.

    And, oRequest['Cookie'] returns only first one of muli-Cookie headers when a request has muti-Cookie headers.

    Should I get the specified Cookie value by checking full lines in the request header and using regexp etc?

     Best regards,

    ------
    Taka

  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 29 Dec 2015 Link to this post

    Hello, Taka--

    I wouldn't expect a valid HTTP request to ever contain more than one Cookie header, although it's probably possible that some client somewhere makes use of such a format. You can use oRequest.headers.AllValues("Cookie") to get a single string with all of the data (delimited by commas), or oRequest.headers.FindAll("Cookie") to get a collection of all Cookie headers.

    You're correct that GetTokenValue presently has a "greedy" problem, whereby if the attribute name is the suffix of some longer string, it is returned. Writing your own regular expression which is specific to Cookies is probably the right way to go.

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top