artanis
[Top][All Lists]
Advanced

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

Re: Me want cookie.


From: Nala Ginrut
Subject: Re: Me want cookie.
Date: Wed, 13 Jan 2021 23:51:39 +0800
User-agent: mu4e 1.4.13; emacs 27.1

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

Attachment: signature.asc
Description: PGP signature


reply via email to

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