响应
相关文档:Koa 响应
相关文档:响应(Response)
响应
状态码
typescript
ctx.response.status = 20
1
状态信息
注意
不可设置中文,否则报错
typescript
ctx.response.message = 'Yes it is OK'
1
响应
typescript
response.body = Anything
1
Anything:
string
响应字符串Buffer
响应Buffer
格式Stream
管道Object
||Array
JSON-字符串化,如果为 对象或数组,则直接转为Json
null
无内容响应
响应头
设置响应头
typescript
ctx.response.set('a', 'b') // 设置单个
ctx.response.set('c', ['aa', 'bb', 'cc']) // 可设置同 key 多个
1
2
2
判断响应头
存在:true
不存在:false
typescript
ctx.response.has('X-RateLimit-Limit');
1