Skip to content

Commit 9887078

Browse files
Add docs from gofiber/fiber@57164ca
1 parent fba5b8f commit 9887078

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

docs/core/api/ctx.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,32 @@ app.Get("/", func(c fiber.Ctx) error {
20452045
})
20462046
```
20472047

2048+
### SendEarlyHints
2049+
2050+
Sends an informational `103 Early Hints` response with one or more
2051+
[`Link` headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Link)
2052+
before the final response. This allows the browser to start preloading
2053+
resources while the server prepares the full response.
2054+
2055+
:::caution
2056+
This feature requires HTTP/2 or newer. Some legacy HTTP/1.1 clients may not
2057+
Early Hints (`103` responses) are supported in HTTP/2 and newer. Older HTTP/1.1 clients may ignore these interim responses or misbehave when receiving them.
2058+
:::
2059+
2060+
```go title="Signature"
2061+
func (c fiber.Ctx) SendEarlyHints(hints []string) error
2062+
```
2063+
2064+
```go title="Example"
2065+
hints := []string{"<https://cdn.com/app.js>; rel=preload; as=script"}
2066+
app.Get("/early", func(c fiber.Ctx) error {
2067+
if err := c.SendEarlyHints(hints); err != nil {
2068+
return err
2069+
}
2070+
return c.SendString("done")
2071+
})
2072+
```
2073+
20482074
### SendFile
20492075

20502076
Transfers the file from the given path. Sets the [Content-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) response HTTP header field based on the **file** extension or format.

docs/core/whats_new.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ testConfig := fiber.TestConfig{
464464
- **IsProxyTrusted**: Checks the trustworthiness of the remote IP.
465465
- **Reset**: Resets context fields for server handlers.
466466
- **Schema**: Similar to Express.js, returns the schema (HTTP or HTTPS) of the request.
467+
- **SendEarlyHints**: Sends `HTTP 103 Early Hints` status code with `Link` headers so browsers can preload resources while the final response is being prepared.
467468
- **SendStream**: Similar to Express.js, sends a stream as the response.
468469
- **SendStreamWriter**: Sends a stream using a writer function.
469470
- **SendString**: Similar to Express.js, sends a string as the response.
@@ -503,6 +504,22 @@ testConfig := fiber.TestConfig{
503504
[RFC 8187](https://www.rfc-editor.org/rfc/rfc8187).
504505
- **Context()**: Renamed to `RequestCtx()` to access the underlying `fasthttp.RequestCtx`.
505506

507+
### SendEarlyHints
508+
509+
`SendEarlyHints` sends an informational [`103 Early Hints`](https://developer.chrome.com/docs/web-platform/early-hints) response with `Link` headers based on the provided `hints` argument. This allows a browser to start preloading assets while the server is still preparing the final response.
510+
511+
```go
512+
hints := []string{"<https://cdn.com/app.js>; rel=preload; as=script"}
513+
app.Get("/early", func(c fiber.Ctx) error {
514+
if err := c.SendEarlyHints(hints); err != nil {
515+
return err
516+
}
517+
return c.SendString("done")
518+
})
519+
```
520+
521+
Older HTTP/1.1 clients may ignore these interim responses or handle them inconsistently.
522+
506523
### SendStreamWriter
507524

508525
In v3, we introduced support for buffered streaming with the addition of the `SendStreamWriter` method:

0 commit comments

Comments
 (0)