From d6e1356b2ad30ea225939ad9f4e74a2d74cb598a Mon Sep 17 00:00:00 2001 From: riabovvo Date: Wed, 27 Oct 2021 13:26:08 +0300 Subject: [PATCH 1/2] MSP-333 implement xml request/response body format support --- handler/handler.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/handler/handler.go b/handler/handler.go index 96a0aa9..84b5dad 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -1,6 +1,7 @@ package handler import ( + "bytes" "encoding/json" "fmt" "net/http" @@ -43,7 +44,6 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) { currentTime := time.Now() appId, adminId, path, resp := h.authenticateAccountingProxy(ctx) - executionTime := time.Since(currentTime) / execution statusCode := ctx.Response.StatusCode() @@ -52,6 +52,8 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) { service.Metrics.UpdateMethodResponseTime(path, executionTime) } + reqContentType := ctx.Request.Header.ContentType() + resContentType := ctx.Response.Header.ContentType() logEnable := config.GetRemote().(*conf.RemoteConfig).JournalSetting.Journal.Enable // nolintlint if logEnable && matcher.JournalMethods.Match(path) { @@ -64,8 +66,8 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) { zap.String("path", path), zap.Int32("application_id", appId), zap.Int64("admin_id", adminId), - zap.Any("request", json.RawMessage(requestBody)), - zap.Any("response", json.RawMessage(responseBody)), + zap.Any("request", castData(requestBody, reqContentType)), + zap.Any("response", castData(responseBody, resContentType)), zap.Error(err), } if err != nil { @@ -76,6 +78,17 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) { } } +var jsonContentType = []byte("application/json") + +func castData(data []byte, contentType []byte) interface{} { + switch { + case bytes.Contains(contentType, jsonContentType): + return json.RawMessage(data) + default: + return fmt.Sprintf("%s", data) + } +} + func (h Handler) authenticateAccountingProxy(ctx *fasthttp.RequestCtx) (int32, int64, string, domain.ProxyResponse) { var ( appId int32 = -1 From 468653eba8a6be50ef04791586e6a7d2748e59dc Mon Sep 17 00:00:00 2001 From: riabovvo Date: Wed, 27 Oct 2021 13:27:44 +0300 Subject: [PATCH 2/2] MSP-333 up version --- .version | 2 +- CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.version b/.version index 6533b66..96d7717 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.8.0 \ No newline at end of file +2.8.1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ca0407..585d3ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v2.8.1 +* add xml format support for new logger ### v2.8.0 * add new logger * remove journal