Passing cookies in Response.Redirect - cookies

I work with Classic ASP (vbscript), I add cookies to the Response like so:
Response.Cookies("mycookie") = "var_cookie"
Then I issue a redirect to "etape2.asp" file:
Response.Redirect("etape2.asp");
On the new page ("etape2.asp") that I am redirected to, I try to retrieve a cookie like so:
Request.Cookies("mycookie");
But the cookie is empty!!
Can anyone think of why the cookies are not being passed?

Might be worthwhile making sure you have set an expiry for the cookie far enough in advance, and set the path to which it applies:
So, in e.g. etape1.asp, do this...
var_cookie_mycookie = "this is the contents of mycookie"
response.cookies("mycookie").expires = now + 1
response.cookies("mycookie").path = "/"
response.cookies("mycookie") = trim(cstr("" & var_cookie_mycookie))
response.redirect "etape2.asp"
And in etape2.asp, do this...
var_cookie_mycookie = trim(cstr("" & request.cookies("mycookie")))
response.write "<p>Value of 'mycookie' cookie: " &_
server.htmlencode(var_cookie_mycookie) &_
"</p>"

Related

Modify a cookie in JMeter to include curly braces around the value

I have the following JSR223 PostProcessor where the captured c_QUID value is to be surrounded by curly braces and used in a cookie. For example if c_QUID is 5575-9878-4848-8897, then I need to set the cookie as {5575-9878-4848-8897}. What can I modify in the below script to do that? As of now it does not add the curly braces.
import org.apache.jmeter.protocol.http.control.*
//Get cookie manager
CookieManager cm = sampler.getCookieManager()
log.info("XXXXXXXXXX QUID " + vars.get("c_QUID"));
Cookie c = new Cookie("QUID", vars.get("c_QUID"), "stage.randomtesting.com", "/", true, 1557578515)
cm.add(c);
Use string concatenation the value:
new Cookie("QUID", "{" + vars.get("c_QUID") + "}",
Shouldn't it be something like:
Cookie c = new Cookie("QUID", "{" + vars.get("c_QUID") + "}", "stage.randomtesting.com", "/", true, 1557578515)
By the way, you might want to use current timestamp as the cookie expiration date because your value of 1557578515 is in the past so the application might not accept it, you might want to replace it with something in the future? See Creating and Testing Dates in JMeter - Learn How article for more details
Also wouldn't that be easier just to define the custom cookie in the HTTP Cookie Manager?

Adding a cookie to DocumentRequest

Using AngleSharp v 0.9.9, I'm loading a page with OpenAsync which sets a bunch of cookies, something like:
var configuration = Configuration.Default.WithHttpClientRequester().WithCookies();
var currentContext = BrowsingContext.New(configuration);
// ....
var doc = context.OpenAsync(url, token);
This works fine and I can see the cookies have been set. For example, I can do this:
var cookieProvider = currentContext.Configuration.Services.OfType<ICookieProvider>().First() as MemoryCookieProvider;
And examine it in the debugger and see the cookies in there (for domain=.share.state.nm.us)
Then I need to submit a post:
var request = new DocumentRequest(postUrl);
request.Method = HttpMethod.Post;
request.Headers["Content-Type"] = "application/x-www-form-urlencoded";
request.Headers["User-Agent"] = userAgent;
//...
Which eventually gets submitted:
var download = loader.DownloadAsync(request);
And I can see (using Fiddler) that it's submitting the cookies from the cookieProvider.
However, I need to add a cookie (and possible change the value in another) and no matter what I try, it doesn't seem to include it. For example, I do this:
cookieProvider.Container.Add(new System.Net.Cookie()
{
Domain = ".share.state.nm.us",
Name = "psback",
Value = "somevalue",
Path = "/"
});
And again I can examine the cookieProvider in the debugger and see the cookie I set. But when I actually submit the request and look in fiddler, the new cookie isn't included.
This seems like it should be really simple, what is the correct way to set a new cookie and have it included in subsequent requests?
I think there are two potential ways to solve this.
either use document.Cookie for setting a new cookie (would require an active document that already is at the desired domain) or
Use a Filter for getting / manipulating the request before its send. This let's you really just change the used cookie container before actually submitting.
The Filter is set in the DefaultLoader configuration. See https://github.com/AngleSharp/AngleSharp/blob/master/src/AngleSharp/ConfigurationExtensions.cs#L152.

Liferay : unable to read full value from cookies in Controller

I want read value from cookie using Java code.
Example:
I have store value in cookie . like email=abc#xyz.com
When I am trying to fetch email value from cookie using below code I am only get "abc". But I want full value "abc#xyz.com"
I am using below code
Cookie[] cookies = renderRequest.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
System.out.print("Name : " + cookie.getName( ) + ", ");
System.out.println("Value: " + cookie.getValue( ));
}
I'm not sure if the RenderRequest gives you the same cookies as the HttpServletRequest: After all, it's a portlet-request. If you have set the value yourself, and you're not getting the same value back, you probably made a mistake encoding the value when you set it.
Also, as you're obviously in a render request handler, that might be the request of someone who is logged in anyway, and there's no need to set a specific cookie: You can just get the value for the currently signed in user (unless you're looking for somebody else's mail address - however that gets stored in the cookie)

varnish split url and change url

Is there a way to split url on varnish or change url structure with it.
I know regsub or regsuball support that but they are not enough in my case.
I would like to change a url and redirect it to another domain.
For example:
http://aaa.test.com/sport/99244-article-hyun-jun-suku-kapa.html?
to redirect below address
http://m.test.com/article-hyun-jun-suku-kapa-sport-99244/
I added some lines in vcl file to do that
set req.http.xrul=regsuball(req.url,".html",""); "clear .html"
set req.http.xrul=regsub(req.http.xrul,"(\d+)","\1"); find numbers --article ID =99244
I can rid of the article ID with
set req.http.xrul=regsub(req.http.xrul,"(\d+)","");
but cannot get just only article ID
set req.http.xrul=regsub(req.http.xrul,"(\d+)","\1"); or any other method
Does varnish support split the url with "-" pattern thus I could redesign the url? Or can we get only articleID with regsub?
Is this what you want to achieve?
set req.http.X-Redirect-URL = regsuball(req.url,"^/([^/]*)/([0-9]+)-([^/]+)\.html$","http://m.test.com/\3-\1-\2");
This is working code tailored to example you provided, just one level of section placement.
If you want to support more levels of sections, you only have to adjust regexp a bit and replace / to - in second step:
set req.http.X-Redirect-URL = "http://m.test.com/" + regsuball(regsuball(req.url, "^/(.*)/([0-9]+)-([^/]+)\.html$", "\3-\1-\2"), "/", "-");
Maybe you need one more refinement. What if URL doesn't match you pattern? X-Redirect-URL will be the very same value as req.url is. You definitely don't want redirect loop, so I suggest to add mark character to the begin of X-Redirect-URL and then test for it.
Let's say:
set req.http.X-Redirect-URL = regsuball(regsuball(req.url, "^/(.*)/([0-9]+)-([^/]+)\.html$", "#\3-\1-\2"), "/", "-");
if(req.http.X-Redirect-URL ~ "^#") {
set req.http.X-Redirect-URL = regsuball(req.http.X-Redirect-URL, "#", "http://m.test.com/");
return(synth(391));
} else {
unset req.http.X-Redirect-URL;
}
and for all cases, you need in vcl_synth:
if (resp.status == 391) {
set resp.status = 301;
set resp.http.Location = req.http.X-Redirect-URL;
return (deliver);
}
Hope this helps.

How to set cookies with yaws

Is there function like php setcookie . If not then how?
EDITED:
yaws_api:setcookie("lang","lang_value", "/"),
yaws_api:find_cookie_val("lang", (A#arg.headers)#headers.cookie),
find_cookie_val returns empty string because setcookie didnt set coockie.
Finally i did it through http header:
out(A) ->
% read
yaws_api:find_cookie_val("lang", (A#arg.headers)#headers.cookie),
% send to browser
[{header,["Set-Cookie:","lang=ruler;","expires="++to_cookie_expire(60*60*24*30)++";"]},
{html, ...}]
end.
to_cookie_expire(SecondsToLive) ->
Seconds = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
DateTime = calendar:gregorian_seconds_to_datetime(Seconds +
SecondsToLive), httpd_util:rfc1123_date(DateTime).
This site provides some example code for yaws and setting cookies:
http://yaws.hyber.org/cookies.yaws