• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript cookie.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中cookie.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: getParamFromRequest

    /**
     * Gets param from the request.
     */
    getParamFromRequest(actionOptions: Action, param: ParamMetadata): any {
        const context = actionOptions.context;
        const request: any = actionOptions.request;
        switch (param.type) {
            case "body":
                return request.body;

            case "body-param":
                return request.body[param.name];

            case "param":
                return context.params[param.name];

            case "params":
                return context.params;

            case "session":
                if (param.name)
                    return context.session[param.name];
                return context.session;

            case "state":
                if (param.name)
                    return context.state[param.name];
                return context.state;

            case "query":
                return context.query[param.name];

            case "queries":
                return context.query;

            case "file":
                return actionOptions.context.req.file;

            case "files":
                return actionOptions.context.req.files;

            case "header":
                return context.headers[param.name.toLowerCase()];

            case "headers":
                return request.headers;

            case "cookie":
                if (!context.headers.cookie) return;
                const cookies = cookie.parse(context.headers.cookie);
                return cookies[param.name];

            case "cookies":
                if (!request.headers.cookie) return {};
                return cookie.parse(request.headers.cookie);
        }
    }
开发者ID:MrDataScientist,项目名称:routing-controllers,代码行数:57,代码来源:KoaDriver.ts


示例2: getParamFromRequest

    /**
     * Gets param from the request.
     */
    getParamFromRequest(action: Action, param: ParamMetadata): any {
        const request: any = action.request;
        switch (param.type) {
            case "body":
                return request.body;

            case "body-param":
                return request.body[param.name];

            case "param":
                return request.params[param.name];

            case "params":
                return request.params;

            case "session":
                if (param.name)
                    return request.session[param.name];

                return request.session;

            case "state":
                throw new Error("@State decorators are not supported by express driver.");

            case "query":
                return request.query[param.name];

            case "queries":
                return request.query;

            case "header":
                return request.headers[param.name.toLowerCase()];

            case "headers":
                return request.headers;

            case "file":
                return request.file;

            case "files":
                return request.files;

            case "cookie":
                if (!request.headers.cookie) return;
                const cookies = cookie.parse(request.headers.cookie);
                return cookies[param.name];

            case "cookies":
                if (!request.headers.cookie) return {};
                return cookie.parse(request.headers.cookie);
        }
    }
开发者ID:MrDataScientist,项目名称:routing-controllers,代码行数:55,代码来源:ExpressDriver.ts


示例3: parseCookie

function parseCookie(header = ''): IRequestData {
    const [platform, connection, build] = ((parserCookie(header) || Object.create(null)).session || '').split(',');
    if (!(build && connection && platform)) {
        return null;
    }
    return { platform, connection, build } as IRequestData;
}
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:7,代码来源:server.ts


示例4: if

	return new Promise<Object>((resolve, reject) => {
		// Get cookies
		const cookies: { [key: string]: string } = cookie.parse(socket.handshake.headers.cookie);

		// Get sesson key
		const sid: string = cookies[config.sessionKey];
		const sidkey: string = sid.match(/s:(.+?)\./)[1];

		// Resolve session
		sessionStore.get(sidkey, (err: any, session: any) => {
			if (err !== null) {
				return console.error(err);
			} else if (session === null) {
				return;
			} else if (typeof session === 'undefined') {
				return;
			}

			const userId: string = session.userId;
			requestApi('account/show', {}, userId).then((user: User) => {
				UserSettings.findOne({
					userId: userId
				}, (_: any, settings: IUserSettings) => {
					user._settings = settings;
					resolve(user);
				});
			});
		});
	});
开发者ID:armchair-philosophy,项目名称:Misskey-Web,代码行数:29,代码来源:get-session-user.ts


示例5: next

        configuration.socketIO.use((socket: any, next: Function) => {
            var handshakeData = socket.request;

            if (handshakeData.headers.cookie) {
                var socketCookie = cookie.parse(handshakeData.headers.cookie);

                var sid = socketCookie['connect.sid'];
                // Backward-compatibility with older version of cookieParser
                var sessionId = (cookieParser.signedCookie || connect.utils.parseSignedCookie)(sid, configuration.sessionStore.secret);

                if (sessionId) {  
                    configuration.sessionStore.store.get(sessionId, (err: any, data: any) => {
                        if (data && data.passport && data.passport.user) {
                            socket.handshake.session = data.passport.user;
                            next();
                        } else {
                            next(new Error("No such user found"));
                        }
                    });
                } else {
                    next(new Error ("Invalid session id"));
                }
            } else {
                next(new Error ("No cookies provided"));
            }
        });
开发者ID:ciuliot,项目名称:github-tracker,代码行数:26,代码来源:server.ts


示例6: getParamFromRequest

 /**
  * Gets param from the request.
  */
 getParamFromRequest(actionOptions: ActionCallbackOptions, param: ParamMetadata): void {
     const request: any = actionOptions.request;
     switch (param.type) {
         case ParamTypes.BODY:
             return request.body;
         case ParamTypes.PARAM:
             return request.params[param.name];
         case ParamTypes.SESSION:
             if (param.name) {
                 return request.session[param.name]; 
             } else {
                 return request.session;
             }
         case ParamTypes.QUERY:
             return request.query[param.name];
         case ParamTypes.HEADER:
             return request.headers[param.name.toLowerCase()];
         case ParamTypes.UPLOADED_FILE:
             return request.file;
         case ParamTypes.UPLOADED_FILES:
             return request.files;
         case ParamTypes.BODY_PARAM:
             return request.body[param.name];
         case ParamTypes.COOKIE:
             if (!request.headers.cookie) return;
             const cookies = cookie.parse(request.headers.cookie);
             return cookies[param.name];
     }
 }
开发者ID:alexproca,项目名称:routing-controllers,代码行数:32,代码来源:ExpressDriver.ts


示例7: getFromCookie

 function getFromCookie() {
     if (!csrfCookieName) {
         return null;
     } else {
         return cookie.parse(document.cookie)[csrfCookieName];
     }
 }
开发者ID:mbraak,项目名称:django-mptt-admin,代码行数:7,代码来源:django_mptt_admin.ts


示例8: getParamFromRequest

 getParamFromRequest(actionOptions: ActionCallbackOptions, param: ParamMetadata): void {
     const context = actionOptions.context;
     const request: any = actionOptions.request;
     switch (param.type) {
         case ParamTypes.BODY:
             return request.body;
         case ParamTypes.PARAM:
             return context.params[param.name];
         case ParamTypes.SESSION:
             throw new Error("@Session decorator is not supported by KoaDriver yet.");
             // TODO return session
         case ParamTypes.QUERY:
             return context.query[param.name];
         case ParamTypes.UPLOADED_FILE:
             throw new Error("@UploadedFile and @UploadedFiles decorators are not supported by KoaDriver yet.");
             // return actionOptions.context.req.file;
         case ParamTypes.UPLOADED_FILES:
             throw new Error("@UploadedFile and @UploadedFiles decorators are not supported by KoaDriver yet.");
             // return actionOptions.context.req.files;
         case ParamTypes.HEADER:
             return context.headers[param.name.toLowerCase()];
         case ParamTypes.BODY_PARAM:
             return request.body[param.name];
         case ParamTypes.COOKIE:
             if (!context.headers.cookie) return;
             const cookies = cookie.parse(context.headers.cookie);
             return cookies[param.name];
     }
 }
开发者ID:alexproca,项目名称:routing-controllers,代码行数:29,代码来源:KoaDriver.ts


示例9: disconnect

 disconnect(socket: SocketIO.Socket) {
     var t: any = cookie.parse(socket.handshake.headers.cookie);
     if (!t.ssid) {
         return;
     }
     let connection: ClientConnection | undefined = this.clients.get(t.ssid);
     if (!connection) {
         return;
     }
     connection.disconnect = setTimeout(() => {
         this.clients.delete(t.ssid);
     });
 }
开发者ID:DemgelOpenSource,项目名称:demgel-sockets,代码行数:13,代码来源:hub-handler.ts


示例10: parseCookie

function parseCookie(cookieStr) {
  const options = {}
  const cookies = []
  const parsed = cookie.parse(cookieStr)
  // tslint:disable-next-line:forin
  for (const k in parsed) {
    if (cookieAttributeNames.indexOf(k) !== -1) {
      options[k] = parsed[k]
      continue
    }
    cookies.push({ name: k, value: parsed[k] })
  }
  return cookies.map(c => Object.assign(c, options))
}
开发者ID:dianpeng,项目名称:fly,代码行数:14,代码来源:cookie_jar.ts



注:本文中的cookie.parse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript cookie-parser.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript convict.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap