Skip to content

Support for cookies #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ppetrosh opened this issue Apr 9, 2018 · 0 comments
Open

Support for cookies #34

ppetrosh opened this issue Apr 9, 2018 · 0 comments
Assignees

Comments

@ppetrosh
Copy link

ppetrosh commented Apr 9, 2018

It would be nice to have cookies supported in Rocky (to automatically set the cookies path to that of the agent to properly scope it):

// If we had http.agentpath(), this would be less error-prone.
local URL = http.agenturl();
local AGENT_ID = split(URL, "/")[2];
// And note that it needs to be the agent *path*, rather than *id*
// because (thought experiment)
// what if we changed agents to live under the 
// '<agent_id>.agent.electricimp.io' domain?

http.onrequest(function(req, res) {
    // This issues cookies with path=/, which means that the browser
    // sends them to any page on agent.electricimp.com;
    // this means that other agents can read it.

    // DON'T:
    //res.header("set-cookie",
    //            "ID=6853b162f152; max-age=3600");

    // DO: Scope the cookie to the agent path.
    res.header("set-cookie",
                "ID=6853b162f152; max-age=3600; path=/" + AGENT_ID);

    res.send(200, "OK");
});
@ppetrosh ppetrosh self-assigned this Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant