当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript cookie.parse函数代码示例

本文整理汇总了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;未经允许,请勿转载。