reprogl
1package container
2
3import (
4"crypto/md5"
5"fmt"
6"net/http"
7"strings"
8)
9
10func RealRemoteAddress(r *http.Request) string {
11addr := r.Header.Get("X-Real-IP")
12if addr == "" {
13addr = r.Header.Get("X-Forwarded-For")
14if addr == "" {
15addr = r.RemoteAddr
16}
17}
18
19return addr
20}
21
22func IsCDN(r *http.Request) bool {
23return strings.Contains(r.Header.Get("Via"), "BunnyCDN")
24}
25
26func MD5(s string) string {
27hash := md5.Sum([]byte(s))
28
29return fmt.Sprintf("%x", hash)
30}
31