类: HTTPRequest
约 947 字大约 3 分钟
2024-06-01
构建固件和导入到JS
HTTPRequest 类由 mg 模块提供:
import { HTTPRequest } from 'mg'简介
HTTPRequest 类用于 mg.HTTPServer 回调函数的参数 req , 不需要创建该类:
类方法
方法 method
原型: method ()
返回 http 请求的方法
"GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT" 等
返回值:
类型string
方法 uri
原型: uri ()
返回 http 请求的 uri
返回值:
类型string
方法 query
原型: query ()
返回 http 请求的 query 部分
返回值:
类型string
方法 proto
原型: proto ()
返回 http 请求的协议
"http", "https", "ws", "wss" 等
返回值:
类型string
方法 header
原型: header (name:string)
返回 http 请求的 header 内容
参数:
name
类型string
参数说明header的名称,如 "Content-Type", "Content-Length", "Host" 等
返回值:
类型string
方法 allHeaders
原型: allHeaders ()
返回 http 请求的所有 header 内容
返回值:
类型object (详见下方类型定义)
说明包含所有请求头的对象,键为 header 名,值为 header 值
返回值类型定义:
{
[key: string]: string
}方法 body
原型: body ()
返回 http 请求的 body 内容
返回值:
类型ArrayBuffer
方法 bodyLength
原型: bodyLength ()
返回 http 请求的 body 数据长度
返回值:
类型number
方法 chunk
原型: chunk ()
返回 http 请求的 body 分段数据内容
所有数据接收完毕后,触发 http.msg 事件。
返回值:
类型ArrayBuffer
方法 chunkLength
原型: chunkLength ()
返回 http 请求的 body 分段数据长度
参考 chunk() 方法
返回值:
类型number
方法 raw
原型: raw ()
返回 http 请求的原始数据内容
返回值:
类型string
方法 rawHead
原型: rawHead ()
返回 http 请求原始的 header 内容
返回值:
类型string
方法 matchURI
原型: matchURI (pattern:string)
由 mg 提供的 uri 匹配检查函数
该函数是对 Mongoose mg_http_match_uri api 的封装
参数:
pattern
类型string
参数说明uri匹配模式
返回值:
类型bool
方法 isCaptivePortalRequest
原型: isCaptivePortalRequest ()
检查是否是 Captive Portal 请求
返回值:
类型bool
