mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-27 04:36:12 +08:00
Add support body to expr fetch func
This commit is contained in:
@@ -6,17 +6,23 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/tcp"
|
"github.com/AlexxIT/go2rtc/pkg/tcp"
|
||||||
"github.com/expr-lang/expr"
|
"github.com/expr-lang/expr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newRequest(method, url string, headers map[string]any) (*http.Request, error) {
|
func newRequest(method, url string, headers map[string]any, body string) (*http.Request, error) {
|
||||||
|
var rd io.Reader
|
||||||
|
|
||||||
if method == "" {
|
if method == "" {
|
||||||
method = "GET"
|
method = "GET"
|
||||||
}
|
}
|
||||||
|
if body != "" {
|
||||||
|
rd = strings.NewReader(body)
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(method, url, nil)
|
req, err := http.NewRequest(method, url, rd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -55,7 +61,8 @@ var Options = []expr.Option{
|
|||||||
options := params[1].(map[string]any)
|
options := params[1].(map[string]any)
|
||||||
method, _ := options["method"].(string)
|
method, _ := options["method"].(string)
|
||||||
headers, _ := options["headers"].(map[string]any)
|
headers, _ := options["headers"].(map[string]any)
|
||||||
req, err = newRequest(method, url, headers)
|
body, _ := options["body"].(string)
|
||||||
|
req, err = newRequest(method, url, headers, body)
|
||||||
} else {
|
} else {
|
||||||
req, err = http.NewRequest("GET", url, nil)
|
req, err = http.NewRequest("GET", url, nil)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user