Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SessionContext

请求上下文对象。

Hierarchy

  • SessionContext

Index

Constructors

constructor

Properties

Private _custom_data

_custom_data: Partial<ToraSession> = {}

Private Readonly cache_expires

cache_expires: number

Private Optional cache_key

cache_key: string

Private Readonly cache_prefix

cache_prefix: string

Accessors

auth_info

  • get auth_info(): undefined | ToraAuthInfo
  • 返回用户信息,如果用户信息不存在,返回 undefined。
    通过声明全局 [[ToraAuthInfo]] 接口定义授权数据类型。

    Returns undefined | ToraAuthInfo

method

  • get method(): undefined | string

path

  • get path(): string

query

  • get query(): Dict<string | string[]>

rawBody

  • get rawBody(): string

real_ip

  • get real_ip(): string
  • 返回请求的客户端 IP 地址,优先使用请求头 X-Real-Ip,如果找不到则使用 X-Forward-For 中的第一个 IP 地址。

    Returns string

url

  • get url(): undefined | string

Methods

clear_cache

  • clear_cache(key: string): Promise<undefined | number>

finish

  • finish(result: any): never

finish_and_cache

  • finish_and_cache<T>(may_be_promised: T | Promise<T>): Promise<T>
  • finish_and_cache<T>(may_be_promised: T | Promise<T>, finish: true): Promise<never>

get_data

  • get_data<M>(key: M): undefined | ToraSession[M]
  • 查询用户自定义数据。
    通过声明全局 [[ToraSession]] 接口定义自定义数据类型。

    Type parameters

    • M: never

    Parameters

    • key: M

    Returns undefined | ToraSession[M]

header

  • header(key: string): undefined | string | string[]
  • 获取指定的请求头。

    Parameters

    • key: string

      请求头名称,比如 Content-Type

    Returns undefined | string | string[]

headers

  • headers(): Dict<string | string[]>

redirect

  • redirect(url: string, alt?: string): never
  • 执行一次向 url 的 302 重定向。
    字符串 “back” 是特别提供 Referrer 支持的,当 Referrer 不存在时,使用 alt 或 /

    e.g.
    this.redirect('back');
    this.redirect('back', '/index.html');
    this.redirect('/login');
    this.redirect('http://google.com');

    Parameters

    • url: string
    • Optional alt: string

    Returns never

response_header

  • response_header(key: string, value: string | number): void
  • 设置响应头。

    Parameters

    • key: string

      响应头字段,比如 Content-Type

    • value: string | number

      需要设置的值

    Returns void

return_if_cache

  • return_if_cache(key: string): Promise<null>

set_data

  • set_data<M>(key: M, value: ToraSession[M]): void
  • 设置用户自定义数据。
    通过声明全局 [[ToraSession]] 接口定义自定义数据类型。

    Type parameters

    • M: never

    Parameters

    • key: M
    • value: ToraSession[M]

    Returns void

Generated using TypeDoc