This is a migrated thread and some comments may be shown as answers.

How to get Cookie value with GetTokenValue()

3 Answers 749 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Taka
Top achievements
Rank 1
Taka asked on 26 Dec 2015, 10:18 PM

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.

3 Answers, 1 is accepted

Sort by
0
Eric Lawrence
Telerik team
answered on 28 Dec 2015, 03:51 PM
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
0
Taka
Top achievements
Rank 1
answered on 29 Dec 2015, 08:40 PM

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

0
Eric Lawrence
Telerik team
answered on 29 Dec 2015, 09:01 PM
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
Tags
Fiddler Classic
Asked by
Taka
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
Taka
Top achievements
Rank 1
Share this question
or