MSP-8438 Add setting for overriding standart json content-header to "application/json; charset=utf-8"

This commit is contained in:
Синельник Тимур Романович committed 2026-08-28 14:07:53 +03:00
1 parent 72f2d37920
commit 2fb58a7195
5 files changed
+50

No files matched your search

+13
View File
@@ -9,6 +9,7 @@ import (
"net/http/httputil"
"net/url"
"strconv"
"strings"
"time"
"isp-gate-service/httperrors"
@@ -79,6 +80,9 @@ func (p Http) Handle(ctx *request.Context) error {
errors.WithMessagef(err, "http proxy to %s", host),
)
}
if ctx.IsJsonUtf8CharsetEnabled() {
reverseProxy.ModifyResponse = addJsonUtf8Charset
}
context, cancel := context.WithTimeout(request.Context(), p.timeout)
defer cancel()
@@ -124,3 +128,12 @@ func setHttpHeaders(ctx *request.Context, header http.Header, skipAuth bool) {
func defaultTransportDialContext(dialer *net.Dialer) func(context.Context, string, string) (net.Conn, error) {
return dialer.DialContext
}
func addJsonUtf8Charset(response *http.Response) error {
contentType := response.Header.Get("Content-Type")
if strings.EqualFold(contentType, "application/json") {
response.Header.Set("Content-Type", "application/json; charset=utf-8")
}
return nil
}