Skip to content

Commit 053763d

Browse files
committed
docs(i18n): middleware (pt-br)
1 parent 7709bc1 commit 053763d

25 files changed

Lines changed: 2827 additions & 0 deletions
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Basic Auth
3+
description: Middleware de autenticação HTTP Basic que valida credenciais de usuário e senha.
4+
sidebar:
5+
order: 1
6+
---
7+
8+
O middleware Basic Auth fornece autenticação básica HTTP.
9+
10+
- Para credenciais válidas, ele chama o próximo handler.
11+
- Para credenciais ausentes ou inválidas, ele envia uma response `401 Unauthorized`.
12+
13+
## Uso
14+
15+
```go
16+
e.Use(middleware.BasicAuth(func(c *echo.Context, username, password string) (bool, error) {
17+
// Use a constant time comparison to prevent timing attacks.
18+
if subtle.ConstantTimeCompare([]byte(username), []byte("joe")) == 1 &&
19+
subtle.ConstantTimeCompare([]byte(password), []byte("secret")) == 1 {
20+
return true, nil
21+
}
22+
return false, nil
23+
}))
24+
```
25+
26+
## Configuração customizada
27+
28+
```go
29+
e.Use(middleware.BasicAuthWithConfig(middleware.BasicAuthConfig{}))
30+
```
31+
32+
## Configuração
33+
34+
```go
35+
type BasicAuthConfig struct {
36+
// Skipper defines a function to skip middleware.
37+
Skipper Skipper
38+
39+
// Validator validates the credentials. If the request contains multiple basic
40+
// auth headers, it is called once for each header until the first valid result.
41+
// Required.
42+
Validator BasicAuthValidator
43+
44+
// Realm is the realm attribute of the WWW-Authenticate header.
45+
// Default value "Restricted".
46+
Realm string
47+
48+
// AllowedCheckLimit sets how many headers are allowed to be checked. This is
49+
// useful in environments such as corporate test setups with application proxies
50+
// restricting access with their own auth scheme.
51+
// Default value 1.
52+
AllowedCheckLimit uint
53+
}
54+
```
55+
56+
O `Validator` tem a assinatura:
57+
58+
```go
59+
type BasicAuthValidator func(c *echo.Context, user string, password string) (bool, error)
60+
```
61+
62+
### Configuração padrão
63+
64+
```go
65+
// Effective defaults applied when fields are left unset.
66+
BasicAuthConfig{
67+
Skipper: DefaultSkipper,
68+
Realm: "Restricted",
69+
}
70+
```
71+
72+
:::caution[Segurança]
73+
Sempre compare credenciais com `subtle.ConstantTimeCompare` para evitar timing attacks.
74+
:::
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Body Dump
3+
description: Capture payloads de request e response e passe-os para um handler para logging ou debugging.
4+
sidebar:
5+
order: 2
6+
---
7+
8+
O middleware Body Dump captura os payloads de request e response e os passa para um
9+
handler registrado. Em geral, ele é usado para debugging ou logging.
10+
11+
:::caution
12+
Evite Body Dump para payloads grandes, como uploads ou downloads de arquivos. Se precisar usá-lo
13+
nessas rotas, adicione uma exceção na função skipper.
14+
:::
15+
16+
## Uso
17+
18+
```go
19+
e := echo.New()
20+
e.Use(middleware.BodyDump(func(c *echo.Context, reqBody, resBody []byte, err error) {
21+
// Handle the request and response bodies.
22+
}))
23+
```
24+
25+
## Configuração customizada
26+
27+
```go
28+
e := echo.New()
29+
e.Use(middleware.BodyDumpWithConfig(middleware.BodyDumpConfig{}))
30+
```
31+
32+
## Configuração
33+
34+
```go
35+
type BodyDumpConfig struct {
36+
// Skipper defines a function to skip middleware.
37+
Skipper Skipper
38+
39+
// Handler receives the request and response payloads and the handler error, if any.
40+
// Required.
41+
Handler BodyDumpHandler
42+
43+
// MaxRequestBytes limits how much of the request body to dump. If the request body
44+
// exceeds this limit, only the first MaxRequestBytes are dumped and the handler
45+
// receives truncated data.
46+
// Default: 5 * MB (5,242,880 bytes). Set to -1 to disable limits (not recommended).
47+
MaxRequestBytes int64
48+
49+
// MaxResponseBytes limits how much of the response body to dump. If the response body
50+
// exceeds this limit, only the first MaxResponseBytes are dumped and the handler
51+
// receives truncated data.
52+
// Default: 5 * MB (5,242,880 bytes). Set to -1 to disable limits (not recommended).
53+
MaxResponseBytes int64
54+
}
55+
```
56+
57+
O `Handler` tem a assinatura:
58+
59+
```go
60+
type BodyDumpHandler func(c *echo.Context, reqBody []byte, resBody []byte, err error)
61+
```
62+
63+
### Configuração padrão
64+
65+
```go
66+
// Effective defaults applied when fields are left unset (Handler is required).
67+
BodyDumpConfig{
68+
Skipper: DefaultSkipper,
69+
MaxRequestBytes: 5 * MB,
70+
MaxResponseBytes: 5 * MB,
71+
}
72+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Body Limit
3+
description: Rejeite requests cujo body exceda um tamanho máximo configurado.
4+
sidebar:
5+
order: 3
6+
---
7+
8+
O middleware Body Limit define o tamanho máximo permitido para o body de um request. Se o tamanho
9+
exceder o limite configurado, ele envia uma response `413 Request Entity Too Large`.
10+
11+
O limite é aplicado tanto ao header de request `Content-Length` quanto ao conteúdo real
12+
lido, o que o torna resistente a headers falsificados. O limite é especificado
13+
em bytes.
14+
15+
## Uso
16+
17+
```go
18+
e := echo.New()
19+
e.Use(middleware.BodyLimit(2_097_152)) // 2 MB
20+
```
21+
22+
## Configuração customizada
23+
24+
```go
25+
e := echo.New()
26+
e.Use(middleware.BodyLimitWithConfig(middleware.BodyLimitConfig{}))
27+
```
28+
29+
## Configuração
30+
31+
```go
32+
type BodyLimitConfig struct {
33+
// Skipper defines a function to skip middleware.
34+
Skipper Skipper
35+
36+
// LimitBytes is the maximum allowed size in bytes for a request body.
37+
LimitBytes int64
38+
}
39+
```
40+
41+
### Configuração padrão
42+
43+
```go
44+
// Effective defaults applied when fields are left unset (Limit is required).
45+
BodyLimitConfig{
46+
Skipper: DefaultSkipper,
47+
}
48+
```

0 commit comments

Comments
 (0)