util.HttpRequest helper to make requests with headers (#2678)

This commit is contained in:
Alan Hamlett
2023-01-30 10:29:06 +01:00
committed by GitHub
parent f7677549ea
commit 0500cc234d
3 changed files with 16 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"os"
"os/user"
"path/filepath"
@@ -493,3 +494,16 @@ func Unzip(src, dest string) error {
return nil
}
// HttpRequest returns a new http.Client for making custom requests (for lua plugins)
func HttpRequest(method string, url string, headers []string) (resp *http.Response, err error) {
client := http.Client{}
req, err := http.NewRequest(method, url, nil)
if err != nil {
return nil, err
}
for i := 0; i < len(headers); i += 2 {
req.Header.Add(headers[i], headers[i+1])
}
return client.Do(req)
}