gecko-dev/remote/test/browser/network/sjs-cookies.sjs
Henrik Skupin 2dd64e92cd Bug 1590098 - [remote] Implement basic support for Network.getCookies. r=remote-protocol-reviewers,ato,maja_zf
This patch adds basic support for retrieving cookies,
which means that it returns the cookies for the currently
active target.

Hereby it has the following limitations:

1. It does not walk the frame tree, and as such only returns
the cookies from the top-level frame. Support for that will
be added once frames can correctly be handled, which means
once support for the JSWindowActor API has been landed.

2. The "urls" parameter is not supported because it is
unclear right now what it actually does. More investigation
is necessary before any implementation can happen.

3. There is no support for the file:// protocol yet.

4. Dot domains aren't taken care of yet.

Differential Revision: https://phabricator.services.mozilla.com/D57614

--HG--
extra : moz-landing-system : lando
2019-12-20 19:38:05 +00:00

44 lines
1.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// eslint-disable-next-line mozilla/reject-importGlobalProperties
Cu.importGlobalProperties(["URLSearchParams"]);
function handleRequest(request, response) {
const queryString = new URLSearchParams(request.queryString);
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
if (queryString.has("name") && queryString.has("value")) {
const name = queryString.get("name");
const value = queryString.get("value");
const path = queryString.get("path") || "/";
const expiry = queryString.get("expiry");
const httpOnly = queryString.has("httpOnly");
const secure = queryString.has("secure");
const sameSite = queryString.get("sameSite");
let cookie = `${name}=${value}; Path=${path}`;
if (expiry) {
cookie += `; Expires=${expiry}`;
}
if (httpOnly) {
cookie += "; HttpOnly";
}
if (sameSite != undefined) {
cookie += `; sameSite=${sameSite}`;
}
if (secure) {
cookie += "; Secure";
}
response.setHeader("Set-Cookie", cookie, true);
response.write(`Set cookie: ${cookie}`);
}
}