Files
photoprism/internal/api/api_client.go
Michael Mayer f5a8c5a45d Auth: Session and ACL enhancements #98 #1746
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 09:01:17 +02:00

30 lines
720 B
Go

package api
import (
"github.com/gin-gonic/gin"
)
// ClientIP returns the client IP address from the request context or a placeholder if it is unknown.
func ClientIP(c *gin.Context) (ip string) {
if c == nil {
// Should never happen.
return "0.0.0.0"
} else if ip = c.ClientIP(); ip == "" {
// Unit tests generally do not set a client IP. According to RFC 5737, the 192.0.2.0/24 subnet
// is intended for use in documentation and examples.
return "192.0.2.42"
}
return ip
}
// UserAgent returns the user agent from the request context or an empty string if it is unknown.
func UserAgent(c *gin.Context) string {
if c == nil {
// Should never happen.
return ""
}
return c.Request.UserAgent()
}