@advanced-rest-client/arc-cookies 中文文档教程

发布于 3年前 浏览 1 项目主页 更新于 3年前

Deprecated

此组件已弃用。 请改用 @advanced-rest-client/app


包含用于处理高级 REST 客户端中的 cookie 和会话的逻辑和 UI 的模块。

在 NPM 上发布

tests

Usage

Installation

npm install --save @advanced-rest-client/arc-cookies

Cookie parser

它解析从服务器接收到的 set-cookie 标头并生成一个 Cookie 对象。

import { Cookies } from '@advanced-rest-client/cookie-parser';

const parser = new Cookies('rememberme=1; domain=foo.com; path=/; ssid=Hy1t5e#oj21.876aak;', 'http://bar.com/');
console.log(parser.cookies);

这相当于:

const cookies = Cookies.parse('...');

第二个参数是正确传递 cookie 所需的请求 URL。

Manipulating cookies

过滤器功能过滤掉不应为给定 URL 考虑的 cookie。 这在 https://tools.ietf.org/html/rfc6265 中定义。

const instance = new Cookies('a=b; domain=foo.com; path=/;', 'http://sub.foo.com/');
const removed = instance.filter();
console.log(removed); // has the cookies because domain does not match

要清除过期的 cookie,只需调用 clearExpired() 函数。

const instance = new Cookies('a=b; expires=0;', 'http://sub.foo.com/');
// wait a second here, then
const removed = instance.filter();
console.log(removed); // the cookie expired

Cookie screen

cookie-manager 在高级 REST 客户端中呈现 cookie 屏幕。 它使用 @advanced-rest-client/arc-events 中定义的事件来请求和传达状态。

<cookie-manager listType="default"></cookie-manager>

Development

git clone https://github.com/advanced-rest-client/arc-cookies
cd arc-cookies
npm install

Running the demo locally

npm start

Running the tests

npm test

Deprecated

This component is deprecated. Use @advanced-rest-client/app instead.


A module that contains the logic and the UIs for handle cookies and sessions in Advanced REST Client.

Published on NPM

tests

Usage

Installation

npm install --save @advanced-rest-client/arc-cookies

Cookie parser

It parses set-cookie header received from the server and produces a Cookie object.

import { Cookies } from '@advanced-rest-client/cookie-parser';

const parser = new Cookies('rememberme=1; domain=foo.com; path=/; ssid=Hy1t5e#oj21.876aak;', 'http://bar.com/');
console.log(parser.cookies);

which is equivalent to:

const cookies = Cookies.parse('...');

The second argument is the request URL needed to properly pase cookies.

Manipulating cookies

The filter function filters out cookies that should not be considered for given URL. This is defined in https://tools.ietf.org/html/rfc6265.

const instance = new Cookies('a=b; domain=foo.com; path=/;', 'http://sub.foo.com/');
const removed = instance.filter();
console.log(removed); // has the cookies because domain does not match

To clear expired cookies just call clearExpired() function.

const instance = new Cookies('a=b; expires=0;', 'http://sub.foo.com/');
// wait a second here, then
const removed = instance.filter();
console.log(removed); // the cookie expired

Cookie screen

The cookie-manager renders the cookies screen in Advanced REST Client. It uses events defined in @advanced-rest-client/arc-events to request and to communicate the state.

<cookie-manager listType="default"></cookie-manager>

Development

git clone https://github.com/advanced-rest-client/arc-cookies
cd arc-cookies
npm install

Running the demo locally

npm start

Running the tests

npm test
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文