Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: pr#1892 #137

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -30,6 +31,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 @@ -67,6 +69,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