Sha256: e46909dd303e0e34359b9ca3d3bbbfe6007d03a9944dc80883174048c0c2f206

Contents?: true

Size: 1.48 KB

Versions: 26

Compression:

Stored size: 1.48 KB

Contents

import cookieUtils from "@bundled-es-modules/cookie";
import { cookieStore } from '../cookieStore.mjs';
function getAllDocumentCookies() {
  return cookieUtils.parse(document.cookie);
}
function getDocumentCookies(request) {
  if (typeof document === "undefined" || typeof location === "undefined") {
    return {};
  }
  switch (request.credentials) {
    case "same-origin": {
      const requestUrl = new URL(request.url);
      return location.origin === requestUrl.origin ? getAllDocumentCookies() : {};
    }
    case "include": {
      return getAllDocumentCookies();
    }
    default: {
      return {};
    }
  }
}
function getAllRequestCookies(request) {
  const requestCookieHeader = request.headers.get("cookie");
  const cookiesFromHeaders = requestCookieHeader ? cookieUtils.parse(requestCookieHeader) : {};
  const cookiesFromDocument = getDocumentCookies(request);
  for (const name in cookiesFromDocument) {
    request.headers.append(
      "cookie",
      cookieUtils.serialize(name, cookiesFromDocument[name])
    );
  }
  const cookiesFromStore = cookieStore.getCookiesSync(request.url);
  const storedCookiesObject = Object.fromEntries(
    cookiesFromStore.map((cookie) => [cookie.key, cookie.value])
  );
  for (const cookie of cookiesFromStore) {
    request.headers.append("cookie", cookie.toString());
  }
  return {
    ...cookiesFromDocument,
    ...storedCookiesObject,
    ...cookiesFromHeaders
  };
}
export {
  getAllRequestCookies
};
//# sourceMappingURL=getRequestCookies.mjs.map

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.25 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.24 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.23 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.22 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.21 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.20 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.19 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.18 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.17 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.16 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.15 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.14 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.13 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.12 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.11 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.10 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.9 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.8 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs
clapton-0.0.7 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/getRequestCookies.mjs