Skip to content

Commit 84beee8

Browse files
Add docs from gofiber/fiber@f9eec85
1 parent a8260a4 commit 84beee8

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

docs/core/api/ctx.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,21 +1344,33 @@ func (c fiber.Ctx) Stale() bool
13441344

13451345
### Subdomains
13461346

1347-
Returns a slice of subdomains in the domain name of the request.
1347+
Returns a slice with the host’s sub-domain labels. The dot-separated parts that precede the registrable domain (`example`) and the top-level domain (ex: `com`).
13481348

1349-
The application property `subdomain offset`, which defaults to `2`, is used for determining the beginning of the subdomain segments.
1349+
The `subdomain offset` (default `2`) tells Fiber how many labels, counting from the right-hand side, are always discarded.
1350+
Passing an `offset` argument lets you override that value for a single call.
13501351

1351-
```go title="Signature"
1352+
```go
13521353
func (c fiber.Ctx) Subdomains(offset ...int) []string
13531354
```
13541355

1355-
```go title="Example"
1356+
| `offset` | Result | Meaning |
1357+
|----------|----------------------------------------|-------------------------------------------------------|
1358+
| *omitted* → **2** | trim 2 right-most labels | drop the registrable domain **and** the TLD |
1359+
| `1` to `len(labels)-1` | trim exactly `offset` right-most labels | custom trimming of available labels |
1360+
| `>= len(labels)` | **return `[]`** | offset exceeds available labels → empty slice |
1361+
| `0` | **return every label** | keep the entire host unchanged |
1362+
| `< 0` | **return `[]`** | negative offsets are invalid → empty slice |
1363+
1364+
#### Example
1365+
1366+
```go
13561367
// Host: "tobi.ferrets.example.com"
13571368
13581369
app.Get("/", func(c fiber.Ctx) error {
1359-
c.Subdomains() // ["ferrets", "tobi"]
1360-
c.Subdomains(1) // ["tobi"]
1361-
1370+
c.Subdomains() // ["tobi", "ferrets"]
1371+
c.Subdomains(1) // ["tobi", "ferrets", "example"]
1372+
c.Subdomains(0) // ["tobi", "ferrets", "example", "com"]
1373+
c.Subdomains(-1) // []
13621374
// ...
13631375
})
13641376
```
@@ -1586,8 +1598,8 @@ app.Get("/", func(c fiber.Ctx) error {
15861598

15871599
Transfers the file from the given path as an `attachment`.
15881600

1589-
Typically, browsers will prompt the user to download. By default, the [Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) header `filename=` parameter is the file path (_this typically appears in the browser dialog_).
1590-
Override this default with the **filename** parameter.
1601+
Typically, browsers will prompt the user to download. By default, the [Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) header `filename=` parameter is the file path (this typically appears in the browser dialog).
1602+
Override this default with the `filename` parameter.
15911603

15921604
```go title="Signature"
15931605
func (c fiber.Ctx) Download(file string, filename ...string) error

0 commit comments

Comments
 (0)