mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
no need to default the Configuration.RemoteAddrHeaders to a list of 'dissalowed' header names, the ctx.RemoteAddr() made unnecessary checks if no X-header was passed, even if they defaulted to false, this will not give a crazy improvement but it's a good practise
Former-commit-id: ba9ed1475a76489df16cac0ed87275b5604f2ad0
This commit is contained in:
@@ -1366,6 +1366,8 @@ func (ctx *context) IsWWW() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
const xForwardedForHeaderKey = "X-Forwarded-For"
|
||||
|
||||
// RemoteAddr tries to parse and return the real client's request IP.
|
||||
//
|
||||
// Based on allowed headers names that can be modified from Configuration.RemoteAddrHeaders.
|
||||
@@ -1377,14 +1379,13 @@ func (ctx *context) IsWWW() bool {
|
||||
// `Configuration.WithRemoteAddrHeader(...)`,
|
||||
// `Configuration.WithoutRemoteAddrHeader(...)` for more.
|
||||
func (ctx *context) RemoteAddr() string {
|
||||
|
||||
remoteHeaders := ctx.Application().ConfigurationReadOnly().GetRemoteAddrHeaders()
|
||||
|
||||
for headerName, enabled := range remoteHeaders {
|
||||
if enabled {
|
||||
headerValue := ctx.GetHeader(headerName)
|
||||
// exception needed for 'X-Forwarded-For' only , if enabled.
|
||||
if headerName == "X-Forwarded-For" {
|
||||
if headerName == xForwardedForHeaderKey {
|
||||
idx := strings.IndexByte(headerValue, ',')
|
||||
if idx >= 0 {
|
||||
headerValue = headerValue[0:idx]
|
||||
|
||||
Reference in New Issue
Block a user