1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-15 01:34:53 +02:00

Adding IP Addresses in log entries

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Ben Huson
2015-09-17 19:17:54 -04:00
committed by Vishal Rana
parent 27cedaf411
commit 799f01a87b
3 changed files with 38 additions and 8 deletions

View File

@ -2,24 +2,41 @@ package middleware
import (
"errors"
"github.com/labstack/echo"
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo"
)
func TestLogger(t *testing.T) {
// Note: Just for the test coverage, not a real test.
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
rec := httptest.NewRecorder()
c := echo.NewContext(req, echo.NewResponse(rec), e)
// Status 2xx
// With X-Real-IP
req.Header.Add(echo.XRealIP, "127.0.0.1")
h := func(c *echo.Context) error {
return c.String(http.StatusOK, "test")
}
Logger()(h)(c)
// With X-Forwarded-For
req.Header.Del(echo.XRealIP)
req.Header.Add(echo.XForwardedFor, "127.0.0.1")
h = func(c *echo.Context) error {
return c.String(http.StatusOK, "test")
}
Logger()(h)(c)
// Status 2xx
h = func(c *echo.Context) error {
return c.String(http.StatusOK, "test")
}
Logger()(h)(c)
// Status 3xx
rec = httptest.NewRecorder()
c = echo.NewContext(req, echo.NewResponse(rec), e)