Setting cookies in a tiled response

How to set a cookie in a tiled response, and then read it from the request. I tried different methods, but none of them set a cookie on the response object.

tried these methods

$self->res->cookies({name => 'foo', value => 'bar'}); $self->res->headers->set_cookie('foo=bar'); $self->res->headers->cookie('foo=bar'); 

plz help !!

thanks.

+6
source share
1 answer

You can use quick access methods directly from the controller:

 # Set $self->cookie(foo => 'bar'); # Get $self->cookie('foo'); 

http://mojolicio.us/perldoc/Mojolicious/Controller#cookie

However, if your intention is to simply save the value and receive it on subsequent requests, there is no need to set cookies directly. Moholytic sessions use signed cookies by default, will handle the complexity of cookies, and will verify that the client has not changed values.

 # Set $self->session(foo => 'bar'); # Get $self->session('foo'); 

http://mojolicio.us/perldoc/Mojolicious/Controller#session

If sessions are the best solution for you, be sure to set the privacy of your application. Also check out: http://mojocasts.com/e4#Session

+11
source

Source: https://habr.com/ru/post/910208/


All Articles