Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: update for 1.0.11


Warning
titleCompatibility

The page is about an earlier version of the pico-engine. It does not apply to version 1.0 of the pico-engine

Picos can be used with a variety of event generators. When the event generator is a browser, it is useful for a pico to be able to set a cookie in the browser. Then, rules reacting to later events, and queries responding to requests from that same browser will have access to the value of the cookie.

...

Note
titleexperimental feature in version 1.0.45.611

This feature is recent, so you will need to do a git pull after updating to version 1.0.45.510, or wait until the feature has been included in version 1.0.45.611 (or higher)

Setting a cookie

Here is a KRL rule which causes a cookie to be set in the browser which, as an event generator, sends a matching event:

Code Block
linenumberstrue
  rule set_cookie {
    select when cookie needed
    pre {
      eci = wrangler:channelchannels(["wellKnown_Rx","Tx_Rx"]).head(){"id"} || meta:eci;
    }
    every {
      send_directive("_cookie",{"cookie": <<wellKnown_Rx=#{eci}; Path=/sky>>});
    }
  }

...

Line 7 sends a directive with a special name, _cookie. At the conclusion of event processing, the pico engine interprets this directive, and will include the appropriate HTTP "Set-Cookie" header. Upon receipt of the response including this header, a browser will remember the cookie name and value, for future interaction with the same pico engine hostname. 

...

Code Block
linenumberstrue
  rule set_cookie {
    select when cookie needed
    pre {
      eci = wrangler:channelchannels(["wellKnown_Rx","Tx_Rx"]).head(){"id"};
    }
    if eci then every {
      send_directive("_cookie",{"cookie": <<wellKnown_Rx=#{eci}; Path=/sky>>});
    }
  }

...