mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-01 19:49:27 +00:00
Remove headers set by a trusted proxy from outputs
This commit is contained in:
@ -3,9 +3,11 @@ package httputils
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/dcarrillo/whatismyip/internal/setting"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -32,6 +34,17 @@ func HeadersToSortedString(headers http.Header) string {
|
||||
return output
|
||||
}
|
||||
|
||||
// GetHeadersWithoutTrustedHeaders return a http.Heade object with the original headers except trusted headers
|
||||
func GetHeadersWithoutTrustedHeaders(ctx *gin.Context) http.Header {
|
||||
h := ctx.Request.Header
|
||||
|
||||
for _, k := range []string{setting.App.TrustedHeader, setting.App.TrustedPortHeader} {
|
||||
delete(h, textproto.CanonicalMIMEHeaderKey(k))
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
// GetLogFormatter returns our custom log format
|
||||
func GetLogFormatter(param gin.LogFormatterParams) string {
|
||||
return fmt.Sprintf("%s - [%s] \"%s %s %s\" %d %d %d %s \"%s\" \"%s\" \"%s\"\n",
|
||||
|
Reference in New Issue
Block a user