summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/v4/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/context.go')
-rw-r--r--vendor/github.com/labstack/echo/v4/context.go20
1 files changed, 7 insertions, 13 deletions
diff --git a/vendor/github.com/labstack/echo/v4/context.go b/vendor/github.com/labstack/echo/v4/context.go
index 0cee48ce..91ab6e48 100644
--- a/vendor/github.com/labstack/echo/v4/context.go
+++ b/vendor/github.com/labstack/echo/v4/context.go
@@ -2,7 +2,6 @@ package echo
import (
"bytes"
- "encoding/json"
"encoding/xml"
"fmt"
"io"
@@ -276,9 +275,9 @@ func (c *context) RealIP() string {
}
// Fall back to legacy behavior
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
- i := strings.IndexAny(ip, ", ")
+ i := strings.IndexAny(ip, ",")
if i > 0 {
- return ip[:i]
+ return strings.TrimSpace(ip[:i])
}
return ip
}
@@ -457,17 +456,16 @@ func (c *context) String(code int, s string) (err error) {
}
func (c *context) jsonPBlob(code int, callback string, i interface{}) (err error) {
- enc := json.NewEncoder(c.response)
- _, pretty := c.QueryParams()["pretty"]
- if c.echo.Debug || pretty {
- enc.SetIndent("", " ")
+ indent := ""
+ if _, pretty := c.QueryParams()["pretty"]; c.echo.Debug || pretty {
+ indent = defaultIndent
}
c.writeContentType(MIMEApplicationJavaScriptCharsetUTF8)
c.response.WriteHeader(code)
if _, err = c.response.Write([]byte(callback + "(")); err != nil {
return
}
- if err = enc.Encode(i); err != nil {
+ if err = c.echo.JSONSerializer.Serialize(c, i, indent); err != nil {
return
}
if _, err = c.response.Write([]byte(");")); err != nil {
@@ -477,13 +475,9 @@ func (c *context) jsonPBlob(code int, callback string, i interface{}) (err error
}
func (c *context) json(code int, i interface{}, indent string) error {
- enc := json.NewEncoder(c.response)
- if indent != "" {
- enc.SetIndent("", indent)
- }
c.writeContentType(MIMEApplicationJSONCharsetUTF8)
c.response.Status = code
- return enc.Encode(i)
+ return c.echo.JSONSerializer.Serialize(c, i, indent)
}
func (c *context) JSON(code int, i interface{}) (err error) {