Net::API::REST::Cookies - Cookie Jar and cookie management
use Net::API::REST::Cookies; my $jar = Net::API::REST::Cookies->new( request => $self, debug => $self->debug ) || return( $self->error( "An error occurred while trying to get the cookie jar." ) ); $jar->fetch; if( $jar->exists( 'my-cookie' ) ) { # do something } # get the cookie my $sid = $jar->get( 'my-cookie' ); # set a new cookie $jar->set( 'my-cookie' => $cookie_object ); # Remove cookie from jar $jar->delete( 'my-cookie' ); return( $jar->make({ name => 'my-cookie', domain => 'example.com', value => 'sid1234567', path => '/', expires => '+10D', ## or alternatively maxage => 864000 ## to make it exclusively accessible by regular http request and not ajax http_only => 1, ## should it be used under ssl only? secure => 1, }) );
v0.2.9
This is a module to handle cookies sent from the web browser, and also to create new cookie to be returned by the server to the web browser.
The reason for this module is because Apache2::Cookie does not work well in decoding cookies, and Cookie::Baker Set-Cookie timestamp format is wrong. They use Mon-09-Jan 2020 12:17:30 GMT where it should be, as per rfc 6265 Mon, 09 Jan 2020 12:17:30 GMT
Set-Cookie
Also APR::Request::Cookie and Apache2::Cookie which is a wrapper around APR::Request::Cookie return a cookie object that returns the value of the cookie upon stringification instead of the full Set-Cookie parameters. Clearly they designed it with a bias leaned toward collecting cookies from the browser.
This initiates the package and take the following parameters:
This is a required parameter to be sent with a value set to a Net::API::REST::Request object
Optional. If set with a positive integer, this will activate verbose debugging message
Given a cookie name, this will remove it from the cookie jar.
However, this will NOT remove it from the web browser by sending a Set-Cookie header.
It returns the value of the cookie removed.
Given a cookie name, this will check if it exists.
Retrieve all possible cookies from the http request received from the web browser.
It returns an hash reference of cookie name => cookie value
Given a cookie name, this will retrieve its value and return it.
Provided with some parameters and this will instantiate a new Net::API::REST::Cookie object with those parameters and return the new object.
Given a cookie name, and a cookie object, this adds it or replace the previous one if any.
This will also add the cookie to the outgoing http headers using the Set-Cookie http header.
Jacques Deguest <jack@deguest.jp>
CPAN ID: jdeguest
https://gitlab.com/jackdeguest/Net-API-REST
Apache2::Cookies, APR::Request::Cookie, Cookie::Baker
Copyright (c) 2018-2019 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install Net::API::REST, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::API::REST
CPAN shell
perl -MCPAN -e shell install Net::API::REST
For more information on module installation, please visit the detailed CPAN module installation guide.