mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
util.HttpRequest helper to make requests with headers (#2678)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user