mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-24 12:08:19 +02:00
device enrollment: fix ip address (#3430)
This commit is contained in:
parent
d1037d784a
commit
a938a23ea2
3 changed files with 44 additions and 5 deletions
|
@ -1,6 +1,9 @@
|
|||
package httputil
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
// StatusDeviceUnauthorized is the status code returned when a client's
|
||||
|
@ -39,3 +42,16 @@ func StatusText(code int) string {
|
|||
}
|
||||
return http.StatusText(code)
|
||||
}
|
||||
|
||||
// GetClientIPAddress gets a client's IP address for an HTTP request.
|
||||
func GetClientIPAddress(r *http.Request) string {
|
||||
if ip := r.Header.Get("X-Envoy-External-Address"); ip != "" {
|
||||
return ip
|
||||
}
|
||||
|
||||
if ip, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
|
||||
return ip
|
||||
}
|
||||
|
||||
return "127.0.0.1"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue