Skip to content

Commit

Permalink
Http: don't send body on GET requests (#14317)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jun 12, 2024
1 parent 0298404 commit 3735c8c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions provider/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"math"
"net/http"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -55,6 +56,7 @@ func NewHTTPProviderFromConfig(other map[string]interface{}) (Provider, error) {
Cache time.Duration
}{
Headers: make(map[string]string),
Method: http.MethodGet,
Scale: 1,
Timeout: request.Timeout,
}
Expand All @@ -66,7 +68,7 @@ func NewHTTPProviderFromConfig(other map[string]interface{}) (Provider, error) {
log := util.NewLogger("http")
http := NewHTTP(
log,
cc.Method,
strings.ToUpper(cc.Method),
cc.URI,
cc.Insecure,
cc.Scale,
Expand Down Expand Up @@ -157,11 +159,11 @@ func (p *HTTP) WithAuth(typ, user, password string) (*HTTP, error) {
}

// request executes the configured request or returns the cached value
func (p *HTTP) request(url string, body ...string) ([]byte, error) {
func (p *HTTP) request(url string, body string) ([]byte, error) {
if time.Since(p.updated) >= p.cache {
var b io.Reader
if len(body) == 1 {
b = strings.NewReader(body[0])
if p.method != http.MethodGet {
b = strings.NewReader(body)
}

tmpl, err := template.New("url").Funcs(sprout.TxtFuncMap()).Parse(url)
Expand All @@ -175,7 +177,7 @@ func (p *HTTP) request(url string, body ...string) ([]byte, error) {
}

// empty method becomes GET
req, err := request.New(strings.ToUpper(p.method), builder.String(), b, p.headers)
req, err := request.New(p.method, builder.String(), b, p.headers)
if err != nil {
return []byte{}, err
}
Expand Down

0 comments on commit 3735c8c

Please sign in to comment.