Interface Request

interface Request {
    basicAuth?: BasicAuth;
    body?: string | object | ArrayBuffer;
    chunked?: ((body: string) => void);
    contentLength?: number;
    disableCanonicalHeader?: boolean;
    discardResponseBody?: boolean;
    headers?: Record<string, string>;
    host?: string;
    maxRedirects?: number;
    method?: string;
    path?: string;
    query?: Record<string, string>;
    scheme?: "http" | "https";
    service?: string;
    timeout?: number;
    url?: string;
}

Properties

basicAuth?: BasicAuth

basicAuth http 基础鉴权。

body?: string | object | ArrayBuffer

body 是要发送的请求体。只有当使用 do 方法时才需要指定。

chunked?: ((body: string) => void)

chunked 当数据以一系列分块的形式进行发送时,如果指定了 chunked 函数,会按行读取响应体, 每次读取到响应体之后回调 chunked 函数。

contentLength?: number

contentLength 记录关联内容的长度。 -1 表示长度未知。>= 0 表示可以从 body 中读取给定的字节数。

disableCanonicalHeader?: boolean

disableCanonicalHeader 是否不遵循标准的请求头格式,设置为 true 代表 headers 的字段名按照用户定义的大小写发送,如 "cookie" 而不是标准首字母大写的 "Cookie"。

discardResponseBody?: boolean

discardResponseBody 丢弃响应体,适用于响应体太大且不需要对响应体内容进行 check 的场景。

headers?: Record<string, string>

headers 包含由客户端发送的请求头字段。

host?: string

host 或者 host:port。

maxRedirects?: number

maxRedirects 重定向跳转次数。

method?: string

method 指定 HTTP 方法(GET、POST、PUT 等)。只有当使用 do 方法时才需要指定。

path?: string

path 表示路径(相对路径省略前导斜杠)。

query?: Record<string, string>

query 是与请求一起发送的 URL 参数。

scheme?: "http" | "https"

scheme 协议 http/https。

service?: string

service 在 PTS 中,我们按照 url 来识别不同 service,基于 serivce 纬度生成报表。 当 url 中包含参数: http://demo.com/{id},不同的 id 将导致请求在报表中被归类为不同的服务; 或者每个 url 含有不同的 ip port 的时候也会被归类为不同的服务; 你可通过指定 service,将此类请求在报表中归类到到同一个服务下。

timeout?: number

timeout 指定此客户端发出的请求的时间限制。 超时包括连接时间、任何重定向和读取响应正文。单位毫秒。

url?: string

url 指定要访问的 URL。只有当使用 do 方法时才需要指定。