This repository was archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
69 lines (53 loc) · 1.59 KB
/
utils.go
File metadata and controls
69 lines (53 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"bytes"
"crypto/tls"
"github.com/go-resty/resty/v2"
"io"
"net/http"
"strconv"
"strings"
"github.com/gin-gonic/gin"
)
func verifyContextHasRequiredValues(c *gin.Context) (errorMessage string, isOk bool) {
urlProxyingTo := c.GetHeader("proxy_url")
if urlProxyingTo == "" {
return "No URL provided", false
}
return "", true
}
func getRemoteURLAndRemoveFromHeaders(c *gin.Context) string {
url := c.GetHeader("proxy_url")
// no need to pass on the proxy_url header
c.Header("proxy_url", "")
return url
}
func getInsecureSkipVerifyAndRemoveFromHeaders(c *gin.Context) bool {
skipVerifyCheck, err := strconv.ParseBool(c.GetHeader("cert_verify"))
// fallback to verifying certs if header value can not be determined
if err != nil {
skipVerifyCheck = false
}
// no need to pass on the skipVerifyCheck header
c.Header("cert_verify", "")
return skipVerifyCheck
}
func extractHeadersFrom(headers http.Header) map[string]string {
processedHeaders := make(map[string]string)
for name, val := range headers {
// http.Header is in the form of map[string][]string, want map[string]string
processedHeaders[name] = strings.Join(val, ", ")
}
return processedHeaders
}
func readcloserToString(i io.ReadCloser) (string, error) {
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(i)
return buf.String(), err
}
func restyClientInit(c *gin.Context) *resty.Client{
skipVerifyCheck := getInsecureSkipVerifyAndRemoveFromHeaders(c)
return resty.New().
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: skipVerifyCheck}).
SetHeaders(extractHeadersFrom(c.Request.Header))
}