Files
photoprism/pkg/net/header/request.go
Michael Mayer 1f4f65e988 Server: Add "force" and "mode" flags for sockets #4673 #4767 #4765 #4467
These changes allow you to force the re-creation of existing Unix domain
sockets and set the permissions of sockets after they have been created.

The flag or variable value for this must be formatted as follows:
--http-host="unix:/var/run/photoprism.sock?force=true&mode=660"

Signed-off-by: Michael Mayer <michael@photoprism.app>
2025-02-04 12:03:00 +01:00

50 lines
1.0 KiB
Go

package header
import (
"github.com/gin-gonic/gin"
)
// Optional HTTP request header names.
const (
Cookie = "Cookie"
Referer = "Referer"
Browser = "Sec-Ch-Ua"
Platform = "Sec-Ch-Ua-Platform"
FetchMode = "Sec-Fetch-Mode"
)
// Standard IP addresses and placeholders.
const (
UnknownIP = "0.0.0.0"
LocalIP = "127.0.0.1"
)
// 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 UnknownIP
} else if c.Request == nil {
return UnknownIP
} else if ip = c.ClientIP(); ip != "" {
return IP(ip, UnknownIP)
} else if ip = c.RemoteIP(); ip != "" {
return IP(ip, UnknownIP)
}
// Tests may not specify an IP address.
return UnknownIP
}
// 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 ""
} else if c.Request == nil {
return ""
}
return c.Request.UserAgent()
}