Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2b4becfd6 |
No files matched your search
@@ -1,3 +1,7 @@
|
|||||||
|
### v5.2.5
|
||||||
|
* добавлено новое поле `enableForceUnescapingUnicode` в конфигурации для очистки тела запроса от экранирования unicode символов при логирование
|
||||||
|
* реализована поддержка очистки тела запроса от экранирования unicode символов для корректного логирования
|
||||||
|
* обновлены зависимости
|
||||||
### v5.2.4
|
### v5.2.4
|
||||||
* обновлены зависимости
|
* обновлены зависимости
|
||||||
### v5.2.3
|
### v5.2.3
|
||||||
|
|||||||
+12
-5
@@ -47,7 +47,7 @@ func NewLocator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli redis.UniversalClient) (http.Handler, error) {
|
func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli redis.UniversalClient) (http.Handler, error) { // nolint:funlen
|
||||||
systemRepo := repository.NewSystem(l.systemCli)
|
systemRepo := repository.NewSystem(l.systemCli)
|
||||||
adminRepo := repository.NewAdmin(l.adminCli)
|
adminRepo := repository.NewAdmin(l.adminCli)
|
||||||
|
|
||||||
@@ -93,8 +93,12 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
|||||||
handler := middleware.Chain(
|
handler := middleware.Chain(
|
||||||
proxyFunc,
|
proxyFunc,
|
||||||
middleware.RequestId(config.EnableClientRequestIdForwarding),
|
middleware.RequestId(config.EnableClientRequestIdForwarding),
|
||||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog,
|
middleware.Logger(
|
||||||
config.Logging.SkipBodyLoggingEndpointPrefixes),
|
l.logger, config.Logging.RequestLogEnable,
|
||||||
|
enableBodyLog,
|
||||||
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
|
),
|
||||||
middleware.ErrorHandler(l.logger),
|
middleware.ErrorHandler(l.logger),
|
||||||
middleware.Authenticate(authentication),
|
middleware.Authenticate(authentication),
|
||||||
middleware.AdminAuthenticate(adminService),
|
middleware.AdminAuthenticate(adminService),
|
||||||
@@ -107,8 +111,11 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
|||||||
handler = middleware.Chain(
|
handler = middleware.Chain(
|
||||||
proxyFunc,
|
proxyFunc,
|
||||||
middleware.RequestId(config.EnableClientRequestIdForwarding),
|
middleware.RequestId(config.EnableClientRequestIdForwarding),
|
||||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog,
|
middleware.Logger(l.logger, config.Logging.RequestLogEnable,
|
||||||
config.Logging.SkipBodyLoggingEndpointPrefixes),
|
enableBodyLog,
|
||||||
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
|
),
|
||||||
middleware.ErrorHandler(l.logger),
|
middleware.ErrorHandler(l.logger),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
"logLevel": "debug",
|
"logLevel": "debug",
|
||||||
"requestLogEnable": true,
|
"requestLogEnable": true,
|
||||||
"bodyLogEnable": false,
|
"bodyLogEnable": false,
|
||||||
"skipBodyLoggingEndpointPrefixes": []
|
"skipBodyLoggingEndpointPrefixes": [],
|
||||||
|
"enableForceUnescapingUnicode": false
|
||||||
},
|
},
|
||||||
"caching": {
|
"caching": {
|
||||||
"authenticationDataInSec": 60,
|
"authenticationDataInSec": 60,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ type Logging struct {
|
|||||||
RequestLogEnable bool `schema:"Включить логирование запросов"`
|
RequestLogEnable bool `schema:"Включить логирование запросов"`
|
||||||
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
||||||
SkipBodyLoggingEndpointPrefixes []string `schema:"регулярные выражения для отключения логирования"`
|
SkipBodyLoggingEndpointPrefixes []string `schema:"регулярные выражения для отключения логирования"`
|
||||||
|
EnableForceUnescapingUnicode bool `schema:"Включить перевод тел запроса из unicode в utf-8, должно быть включено логирование тел запросов и ответов"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Caching struct {
|
type Caching struct {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ require (
|
|||||||
github.com/redis/go-redis/v9 v9.7.3
|
github.com/redis/go-redis/v9 v9.7.3
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
github.com/tomakado/websocketproxy v0.1.0
|
github.com/tomakado/websocketproxy v0.1.0
|
||||||
github.com/txix-open/isp-kit v1.46.0
|
github.com/txix-open/isp-kit v1.47.0
|
||||||
github.com/txix-open/jsonschema v1.2.0
|
github.com/txix-open/jsonschema v1.2.0
|
||||||
golang.org/x/net v0.39.0
|
golang.org/x/net v0.39.0
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250421163800-61c742ae3ef0
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250421163800-61c742ae3ef0
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg
|
|||||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||||
github.com/txix-open/grmq v1.7.0 h1:nwenrlxEjXpK0EBCa/WbIxK+y0mF2pZxNKbheFjQVsI=
|
github.com/txix-open/grmq v1.7.0 h1:nwenrlxEjXpK0EBCa/WbIxK+y0mF2pZxNKbheFjQVsI=
|
||||||
github.com/txix-open/grmq v1.7.0/go.mod h1:DAfbV4jLyxQBLG8OYJVy8kCbhucdlu/C/wl+nUDc9p8=
|
github.com/txix-open/grmq v1.7.0/go.mod h1:DAfbV4jLyxQBLG8OYJVy8kCbhucdlu/C/wl+nUDc9p8=
|
||||||
github.com/txix-open/isp-kit v1.46.0 h1:Rqw5X+501vEwMv6oGvC6sYU1++1XiTvxt6Ja/CD7lRw=
|
github.com/txix-open/isp-kit v1.47.0 h1:WDSIgSbLWtOkqJwVFYT0QF2Lcz4JwreET6+jKoRk1vM=
|
||||||
github.com/txix-open/isp-kit v1.46.0/go.mod h1:tWz/RGhRHx+JQZa5j1srR9kzL5YkIed3350SQ+FV1Wc=
|
github.com/txix-open/isp-kit v1.47.0/go.mod h1:gCAI51RReCzgSCsml4ykFEqsWfWCtuP140xpQ/OFB+Q=
|
||||||
github.com/txix-open/jsonschema v1.2.0 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
|
github.com/txix-open/jsonschema v1.2.0 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
|
||||||
github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To=
|
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To=
|
||||||
|
|||||||
+29
-5
@@ -3,6 +3,7 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -14,6 +15,10 @@ import (
|
|||||||
"isp-gate-service/request"
|
"isp-gate-service/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
unicodeEscapePrefix = []byte("\\u") // nolint:gochecknoglobals
|
||||||
|
)
|
||||||
|
|
||||||
type scSource interface {
|
type scSource interface {
|
||||||
StatusCode() int
|
StatusCode() int
|
||||||
}
|
}
|
||||||
@@ -43,11 +48,12 @@ func (w *writerWrapper) WriteHeader(statusCode int) {
|
|||||||
w.ResponseWriter.WriteHeader(statusCode)
|
w.ResponseWriter.WriteHeader(statusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Logger(
|
func Logger( // nolint:gocognit
|
||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
enableRequestLogging bool,
|
enableRequestLogging bool,
|
||||||
enableBodyLogging bool,
|
enableBodyLogging bool,
|
||||||
skipBodyLoggingEndpointPrefixes []string,
|
skipBodyLoggingEndpointPrefixes []string,
|
||||||
|
enableForceUnescapingUnicode bool,
|
||||||
) Middleware {
|
) Middleware {
|
||||||
return func(next Handler) Handler {
|
return func(next Handler) Handler {
|
||||||
return HandlerFunc(func(ctx *request.Context) error {
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
@@ -108,10 +114,13 @@ func Logger(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if logBodyFromCurrenRequest {
|
if logBodyFromCurrenRequest {
|
||||||
fields = append(fields,
|
if enableForceUnescapingUnicode && bytes.Contains(buf.RequestBody(), unicodeEscapePrefix) {
|
||||||
log.ByteString("request", buf.RequestBody()),
|
fields = append(fields, log.ByteString("request", forceUnescapingUnicode(buf.RequestBody())))
|
||||||
log.ByteString("response", buf.ResponseBody()),
|
} else {
|
||||||
)
|
fields = append(fields, log.ByteString("request", buf.RequestBody()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fields = append(fields, log.ByteString("response", buf.ResponseBody()))
|
||||||
}
|
}
|
||||||
logger.Debug(ctx.Context(), "log request", fields...)
|
logger.Debug(ctx.Context(), "log request", fields...)
|
||||||
|
|
||||||
@@ -119,3 +128,18 @@ func Logger(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func forceUnescapingUnicode(data []byte) []byte {
|
||||||
|
var body any
|
||||||
|
err := json.Unmarshal(data, &body)
|
||||||
|
if err != nil {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
newData, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
return newData
|
||||||
|
}
|
||||||
Reference in new issue
Block a user