Skip to content

Commit

Permalink
Update: f2982a2...29c2af1
Browse files Browse the repository at this point in the history
  • Loading branch information
fralonra committed Oct 9, 2020
1 parent 4e77389 commit 8f13cad
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 37 deletions.
2 changes: 2 additions & 0 deletions docs/Decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fastify.get('/', (req, reply) => {
})
```

装饰器的初始值应该尽可能地与其未来将被设置的值接近。例如,字符串类型的装饰器的初始值为 `''`,对象或函数类型的初始值为 `null`

更多此话题的内容,请见 [JavaScript engine fundamentals: Shapes and Inline Caches](https://web.archive.org/web/20200201163000/https://mathiasbynens.be/notes/shapes-ics)

### 使用方法
Expand Down
17 changes: 17 additions & 0 deletions docs/Reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [.callNotFound()](#callnotfound)
- [.getResponseTime()](#getresponsetime)
- [.type(contentType)](#typecontenttype)
- [.raw](#raw)
- [.serializer(func)](#serializerfunc)
- [.sent](#sent)
- [.send(data)](#senddata)
Expand Down Expand Up @@ -177,6 +178,22 @@ reply

请看 [`.send()`](#send) 了解更多关于发送不同类型值的信息。

<a name="raw"></a>
### .raw
Node 核心的 [`http.ServerResponse`](https://nodejs.org/dist/latest/docs/api/http.html#http_class_http_serverresponse) 对象。使用 `Reply.raw` 上的方法会跳过 fastify 对 http 响应的处理逻辑,所以请谨慎使用。以下是一个例子:

```js
app.get('/cookie-2', (req, reply) => {
reply.setCookie('session', 'value', { secure: false }) // 这行不会应用

// 在这个例子里我们只使用了 nodejs 的 http 响应对象
reply.raw.writeHead(200, { 'Content-Type': 'text/plain' })
reply.raw.write('ok')
reply.raw.end()
})
```
[Reply.md#getheaders](Reply.md#getheaders) 里有另一个误用 `Reply.raw` 的例子。

<a name="sent"></a>
### .sent

Expand Down
4 changes: 4 additions & 0 deletions docs/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ fastify.register(function (instance, opts, done) {
#### log
日志的实例,详见[这里](Logging.md)。

<a name="version"></a>
#### version
Fastify 实例的版本。可在插件中使用。详见[插件](Plugins.md#handle-the-scope)一文。

<a name="inject"></a>
#### inject
伪造 http 注入 (作为测试之用) 。请看[更多内容](Testing.md#inject)。
Expand Down
Loading

0 comments on commit 8f13cad

Please sign in to comment.