git.iko.soy/typeable/oauth2-proxy
on reference-generator help sign in
35 lines 864 B history raw
1package util
3import (
4 "crypto/x509"
5 "fmt"
6 "io/ioutil"
7 "net/http"
8)
10func GetCertPool(paths []string) (*x509.CertPool, error) {
11 if len(paths) == 0 {
12 return nil, fmt.Errorf("invalid empty list of Root CAs file paths")
13 }
14 pool := x509.NewCertPool()
15 for _, path := range paths {
16 // Cert paths are a configurable option
17 data, err := ioutil.ReadFile(path) // #nosec G304
18 if err != nil {
19 return nil, fmt.Errorf("certificate authority file (%s) could not be read - %s", path, err)
20 }
21 if !pool.AppendCertsFromPEM(data) {
22 return nil, fmt.Errorf("loading certificate authority (%s) failed", path)
23 }
24 }
25 return pool, nil
28// GetRequestHost return the request host header or X-Forwarded-Host if present
29func GetRequestHost(req *http.Request) string {
30 host := req.Header.Get("X-Forwarded-Host")
31 if host == "" {
32 host = req.Host
33 }
34 return host