-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
51 lines (43 loc) · 1.15 KB
/
utils.go
File metadata and controls
51 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package peerdb
import (
"context"
"net"
"net/http"
"strings"
"gitlab.com/tozd/waf"
internalStore "gitlab.com/peerdb/peerdb/internal/store"
)
// WithFallbackDBContext returns context with fallback context values which are used
// to set schema and application name on PostgreSQL connections when it is not part
// of the request.
func WithFallbackDBContext(ctx context.Context, schema, name string) context.Context {
return internalStore.WithFallbackDBContext(ctx, schema, name)
}
func hasConnectionUpgrade(req *http.Request) bool {
for _, value := range strings.Split(req.Header.Get("Connection"), ",") {
if strings.ToLower(strings.TrimSpace(value)) == "upgrade" {
return true
}
}
return false
}
// Same as in zerolog/hlog/hlog.go.
func getHost(hostPort string) string {
if hostPort == "" {
return ""
}
host, _, err := net.SplitHostPort(hostPort)
if err != nil {
return hostPort
}
return host
}
func getRequestWithFallback() func(context.Context) (string, string) {
return internalStore.GetRequestWithFallback(func(ctx context.Context) string {
site, ok := waf.GetSite[*Site](ctx)
if ok {
return site.Schema
}
return ""
})
}