Skip to content

Commit

Permalink
Update: pr#1892
Browse files Browse the repository at this point in the history
  • Loading branch information
fralonra committed Oct 14, 2019
1 parent c65ab8b commit 7c1571c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/Reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [回复](#reply)
- [简介](#introduction)
- [.code(statusCode)](#codestatuscode)
- [.statusCode](#statusCode)
- [.header(key, value)](#headerkey-value)
- [.getHeader(key)](#getheaderkey)
- [.removeHeader(key)](#removeheaderkey)
Expand Down Expand Up @@ -31,6 +32,7 @@ Reply 是 Fastify 的一个核心对象。它暴露了以下函数及属性:

- `.code(statusCode)` - 设置状态码。
- `.status(statusCode)` - `.code(statusCode)` 的别名。
- `.statusCode` - 获取或设置 HTTP 状态码。
- `.header(name, value)` - 设置响应 header。
- `.getHeader(name)` - 获取某个 header 的值。
- `.removeHeader(key)` - 清除已设置的 header 的值。
Expand Down Expand Up @@ -68,6 +70,15 @@ fastify.get('/', {config: {foo: 'bar'}}, function (request, reply) {
### .code(statusCode)
如果没有设置 `reply.code``statusCode` 会是 `200`

<a name="statusCode"></a>
### .statusCode
获取或设置 HTTP 状态码。作为 setter 使用时,是 `reply.code()` 的别名。
```js
if (reply.statusCode >= 299) {
reply.statusCode = 500
}
```

<a name="header"></a>
### .header(key, value)
设置响应 header。如果值被省略或为 undefined,将被强制设成 `''`
Expand Down

0 comments on commit 7c1571c

Please sign in to comment.