mirror of
https://github.com/kemko/nomad.git
synced 2026-01-13 13:55:42 +03:00
Merge pull request #14023 from hashicorp/nsd-check-body
nsd: add support for setting request body in http checks
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
@@ -163,6 +164,7 @@ func (c *checker) checkHTTP(ctx context.Context, qc *QueryContext, q *Query) *st
|
||||
return qr
|
||||
}
|
||||
request.Header = q.Headers
|
||||
request.Body = io.NopCloser(strings.NewReader(q.Body))
|
||||
request = request.WithContext(ctx)
|
||||
|
||||
result, err := c.httpClient.Do(request)
|
||||
|
||||
@@ -269,6 +269,12 @@ func TestChecker_Do_HTTP_extras(t *testing.T) {
|
||||
[2]string{"Authorization", "Basic ZWxhc3RpYzpjaGFuZ2VtZQ=="},
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "with body",
|
||||
method: "POST",
|
||||
headers: makeHeaders(encoding, agent),
|
||||
body: "some payload",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
@@ -295,6 +301,7 @@ func TestChecker_Do_HTTP_extras(t *testing.T) {
|
||||
Path: "/",
|
||||
Method: tc.method,
|
||||
Headers: tc.headers,
|
||||
Body: tc.body,
|
||||
}
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
@@ -24,6 +24,7 @@ func GetCheckQuery(c *structs.ServiceCheck) *Query {
|
||||
Path: c.Path,
|
||||
Method: c.Method,
|
||||
Headers: helper.CopyMap(c.Header),
|
||||
Body: c.Body,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +43,7 @@ type Query struct {
|
||||
Path string // http checks only
|
||||
Method string // http checks only
|
||||
Headers http.Header // http checks only
|
||||
Body string // http checks only
|
||||
}
|
||||
|
||||
// A QueryContext contains allocation and service parameters necessary for
|
||||
|
||||
@@ -350,11 +350,6 @@ func (sc *ServiceCheck) validateNomad() error {
|
||||
if sc.Method != "" && !helper.IsMethodHTTP(sc.Method) {
|
||||
return fmt.Errorf("method type %q not supported in Nomad http check", sc.Method)
|
||||
}
|
||||
|
||||
// todo(shoenig) support body
|
||||
if len(sc.Body) > 0 {
|
||||
return fmt.Errorf("http checks may not set Body in Nomad services")
|
||||
}
|
||||
}
|
||||
|
||||
// success_before_passing is consul only
|
||||
|
||||
@@ -336,10 +336,9 @@ func TestServiceCheck_validateNomad(t *testing.T) {
|
||||
Interval: 3 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
Path: "/health",
|
||||
Method: "GET",
|
||||
Body: "blah",
|
||||
Method: "POST",
|
||||
Body: "this is a request payload!",
|
||||
},
|
||||
exp: `http checks may not set Body in Nomad services`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user