artanis
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Me want cookie.


From: Mortimer Cladwell
Subject: Re: Me want cookie.
Date: Fri, 15 Jan 2021 06:05:32 -0500

Hi Nala,

Below is my test of cookies with the fix/ssql-guile3 branch on Debian 10 Chromium browser.

Controllers:
-----BEGIN-------------------------------------------------------------------
(plateset-define cset
(options #:cookies '(names prjid sid))
(lambda (rc)
  (let* ((dummy (:cookies-set! rc 'prjid "prjid" "1000"))
 (result "empty")
 (cookies (rc-cookie rc)))
    (view-render "test" (the-environment)))))

(plateset-define check
(lambda (rc)
  (let* ((result (:cookies-check rc "prjid"))
 (cookies (rc-cookie rc)))
    (view-render "test" (the-environment)))))

(plateset-define ref
(lambda (rc)
  (let* ((result (:cookies-ref rc 'prjid "prjid"))
 (cookies (rc-cookie rc)))
    (view-render "test" (the-environment)))))

 (plateset-define haskey
(lambda (rc)
  (let* ((cookies (rc-cookie rc))
 (result (cookie-has-key? cookies "prjid")) )
    (view-render "test" (the-environment)))))

(plateset-define remove
(options #:cookies '(names prjid sid))
(lambda (rc)
  (let* ((dummy (:cookies-remove! rc 'prjid))
 (result "empty")
 (cookies (rc-cookie rc)) )
   (view-render "test" (the-environment)))))

------END----------------------------------------------------------------------


----BEGIN-----------View-------------------------------------------------------

result: <%= result %><br>
cookies:  <%= cookies %><br>
 
 ------END----------------------------------------------------------------------

Below I show the view results as well as what I see in the Chromium cookies browser. The results are in the chronological order of submission of each of the controllers. I start with no cookies.  I am showing the test page source code so we can see the structure contents:

1 ---------------------

127.0.0.1:3000/plateset/check
 
result: prjid<br>
cookies:  ()<br>
Chromium cookies console: empty
 
2 ------------------------

127.0.0.1:3000/plateset/ref

result: prjid<br>
cookies:  ()<br>  
Chromium cookies console: empty
 
3 ---------------------

127.0.0.1:3000/plateset/haskey

result: #f<br>
cookies:  ()<br>
Chromium cookies console: empty
       
4 ---------------------

127.0.0.1:3000/plateset/cset
   
result: empty<br>
cookies:  ()<br>
Chromium cookies console: cookie and value visible
     
5 ---------------------

  127.0.0.1:3000/plateset/check

result: prjid<br>
cookies:  (#<cookie nvp: (("prjid" "1000")) expires: #f domain: #f path: #f secure: #f http-only: #f>)<br>    
Chromium cookies console: cookie and value visible
   
6 ---------------------

  127.0.0.1:3000/plateset/ref

result: prjid<br>
cookies:  (#<cookie nvp: (("prjid" "1000")) expires: #f domain: #f path: #f secure: #f http-only: #f>)<br>    
Chromium cookies console: cookie and value visible
   
7 ---------------------

127.0.0.1:3000/plateset/haskey

result: #<cookie nvp: (("prjid" "1000")) expires: #f domain: #f path: #f secure: #f http-only: #f><br>
cookies:  (#<cookie nvp: (("prjid" "1000")) expires: #f domain: #f path: #f secure: #f http-only: #f>)<br>
Chromium cookies console: cookie and value visible
   
8 ---------------------
   

Manually delete cookie in the Chromium console

  results repeat as at step 1 onward....

=======================================

Results:

** :cookies-set!  Seems to work - adds a cookie that is visible in the browser console

** :cookies-check & :cookies-ref report the cookie name "prjid" independent of cookies existence

** cookie-has-key?  initially #f. After :cookes-set! contains the cookies structure regardless of which additional commands are issued including :cookies-remove!  Only manually deleting the cookie in the browser console resets cookie-has-key? to #f

** (cookies (rc-cookie rc))  cookies variable is loaded with the cookies structure after :cookies-set!. No other commands seem to affect it. Manual deletion of the cookie in the browser console resets cookies to #f

** (:cookies-remove! rc key) ; remove cookie from client <== from the manual. When I tried there was no effect on browser cookies. You did not mention this in your last message indicating the API. Is it supposed to work - can we use it?


It seems like the (cookies (rc-cookie rc))  variable is accurately reflecting the contents of the browser cookies.

What is supposed to be the difference between :cookies-check & :cookies-ref ?  I thought (:cookies-ref rc 'prjid "prjid") would retrieve the value - if not what does it do and is there a method to retrieve the value '1000'? cookie-has-key? gives the entire structure.

Thanks
Mortimer




On Wed, Jan 13, 2021 at 10:51 AM Nala Ginrut <mulei@gnu.org> wrote:

I've pushed it to fix/ssql-guile3, please try it.

Best regards.


Mortimer Cladwell writes:

> Thanks Nala! Could you put the fix in the fix/ssql-guile3 branch?
> Mortimer
>
> On Wed, Jan 13, 2021 at 1:37 AM Nala Ginrut <mulei@gnu.org> wrote:
>
>>
>> Hi Mortimer!
>> This issue is caused by the misuse of :cookies-ref
>>
>> In the current design of Artanis, these APIs are used for controling the
>> cookies for the client:
>> :cookies-ref
>> :cookies-set!
>> :cookies-setattr!
>> :cookies-update!
>> And :cookies-update! is automatically triggered by the hook each time
>> the server resonse to the cilent. So users never call it directly.
>>
>> For server-side, the correct function to fetch the cookie from client is
>> `cookie-has-key?' in (artanis cookie). So your code should look like this:
>> -------------------cut-----------------------
>> (import (artanis cookie))
>>
>> (plateset-define
>> test
>> (lambda (rc)
>> (let* ((cookies (rc-cookie rc))
>> (acookie (cookie-has-key? cookies "prjid")))
>> (view-render "test" (the-environment)))))
>> -------------------end--------------------------
>>
>> Please notice that you don't have to set
>> (options #:cookies '(names prjid sid))
>> if you only want to handle the cookie in the server-side. This option is
>> to create and modify the cookie and pass them to the client. So it
>> should be used in your `add' and `delete' controller.
>>
>> It's my mistake to forget to add this function to the API, now I've
>> added :cookies-check, so you can rewrite your code as:
>> ----------------------cut--------------------------
>> (plateset-define
>> test
>> (lambda (rc)
>> (let* ((cookies (rc-cookie rc))
>> (acookie (:cookies-check rc "prjid")))
>> (view-render "test" (the-environment)))))
>> ----------------------end--------------------------
>>
>> Please notice that the key is a string.
>>
>> This fix appears in the master and guile3 branch now.
>>
>> Best regards.
>>
>>
>> Mortimer Cladwell writes:
>>
>> > Hello!
>> >
>> > Cookies don't seem to be working for me.  I test the below controllers on
>> > both Chrome and Firefox.
>> > On Debian 10, Guile 3.0.4 using Artanis branch fix/ssql-guile3.
>> >
>> > Controllers:
>> >
>> > ---BEGIN-----/plateset/test----------------------------------------------
>> > (plateset-define test
>> >  (options #:cookies '(names prjid sid))
>> >  (lambda (rc)
>> >    (let* ((cookies (rc-cookie rc))
>> >  (acookie (:cookies-ref rc 'prjid "prjid")))
>> >  (view-render "test" (the-environment)))))
>> > ---END-------------------------------------------------------------------
>> >
>> > ---BEGIN-----/plateset/testadd-------------------------------------------
>> > (plateset-define testadd
>> >  (options #:cookies '(names prjid sid))
>> >  (lambda (rc)
>> >    (let* ((dummy (:cookies-set! rc 'prjid "prjid" "1000"))
>> >  (cookies (rc-cookie rc))
>> >  (acookie (:cookies-ref rc 'prjid "prjid")))
>> >    (view-render "test" (the-environment)))))
>> > ---END-------------------------------------------------------------------
>> >
>> > ---BEGIN-----/plateset/testdelete----------------------------------------
>> > (plateset-define testdelete
>> >  (options #:cookies '(names prjid sid))
>> >   (lambda (rc)
>> >   (let* ((dummy (:cookies-remove! rc "prjid"))
>> >  (cookies (rc-cookie rc))
>> >  (acookie (:cookies-ref rc 'prjid "prjid")))
>> >    (view-render "test" (the-environment)))))
>> > ---END-------------------------------------------------------------------
>> >
>> > View:
>> >
>> > ---BEGIN------test.html.tpl----------------------------------------------
>> > <html></body>
>> >   <h1>Test</h1><br><br>
>> >   cookies: <%= cookies %><br>
>> >   acookie:  <%= acookie %><br>
>> > </body></html>
>> > ---END-------------------------------------------------------------------
>> >
>> > Firefox results first:
>> >
>> > I clear all cookies and load /plateset/test and see the view:
>> > cookies: ()
>> > acookie: #f
>> >
>> > I load /plateset/testadd and see:
>> > cookies: ()
>> > acookie: 1000
>> > "prjid" is present in the cookies via browser console.
>> >
>> > I reload /plateset/test and see:
>> > cookies: (#)
>> > acookie: #f
>> > "prjid" is still present in the cookies via browser console!
>> > If I look at the terminal (art work) output, I also see "prjid" in the
>> > header:
>> >
>> >  (connection keep-alive) (cookie . "prjid=1000")
>> (upgrade-insecure-requests
>> > . "1") (if-modified-since . #<date nanosecond: 0 second: 30 minute: 39
>> > hour: 14 day: 9 month: 12 year: 2020 zone-offset: 0>)) meta: () port:
>> > #<input-output: socket 22>>
>> >
>> >  If I load /plateset/testdelete I see:
>> >  cookies: (#)
>> > acookie: #f
>> > But "prjid" is present in both header and cookies on the browser console!
>> >
>> > Chrome results:
>> >
>> > HTML view gives the same results as Firefox however cookies never appear
>> in
>> > the browser console nor in the header visible in art work terminal
>> output.
>> >
>> > My expectation is that (rc-cookie rc) would provide a list of key/value
>> > pairs of all cookies - retrieved from the header - while (:cookies-ref rc
>> > 'prjid "prjid") provides the value of a single cookie, "prjid" in this
>> > case.  Is that correct?
>> >
>> > (rc-cookie rc) does not seem to work at all.
>> > I can add a cookie with (:cookies-set! rc 'prjid "prjid" "1000") in
>> > Firefox, but I can only retrieve that cookie in the same method
>> invocation
>> > i.e. all future attempts at retrieval fail.
>> > (:cookies-remove! rc "prjid") does not seem to work in Firefox.  Since a
>> > cookie is never visible in Chrome web console, can't evaluate
>> > :cookies-remove!
>> > What am I doing wrong?
>> > Thanks
>> > Mortimer
>>
>>
>> --
>> GNU Powered it
>> GPL Protected it
>> GOD Blessed it
>> HFG - NalaGinrut
>> Fingerprint F53B 4C56 95B5 E4D5 6093 4324 8469 6772 846A 0058
>>


--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
Fingerprint F53B 4C56 95B5 E4D5 6093 4324 8469 6772 846A 0058

reply via email to

[Prev in Thread] Current Thread [Next in Thread]