From 500173b939664c0399f5430230d8ae33858f2039 Mon Sep 17 00:00:00 2001 From: Andrew Hemming Date: Wed, 7 Dec 2016 15:13:15 +0000 Subject: [PATCH] Added support for posting a body of content (#86) --- README.md | 8 ++++++++ http.go | 5 +++++ main.go | 1 + 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 704fcdb..b4b9591 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,14 @@ modules: insecure_skip_verify: false protocol: "tcp" # accepts "tcp/tcp4/tcp6", defaults to "tcp" preferred_ip_protocol: "ip4" # used for "tcp", defaults to "ip6" + http_post_2xx: + prober: http + timeout: 5s + http: + method: POST + headers: + Content-Type: application/json + body: '{}' tcp_connect_v4_example: prober: tcp timeout: 5s diff --git a/http.go b/http.go index 5bf9473..8993f92 100644 --- a/http.go +++ b/http.go @@ -153,6 +153,11 @@ func probeHTTP(target string, w http.ResponseWriter, module Module) (success boo request.Header.Set(key, value) } + // If a body is configured, add it to the request + if config.Body != "" { + request.Body = ioutil.NopCloser(strings.NewReader(config.Body)) + } + resp, err := client.Do(request) // Err won't be nil if redirects were turned off. See https://github.com/golang/go/issues/3795 if err != nil && resp == nil { diff --git a/main.go b/main.go index e5a0523..d6901ed 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,7 @@ type HTTPProbe struct { TLSConfig config.TLSConfig `yaml:"tls_config"` Protocol string `yaml:"protocol"` // Defaults to "tcp". PreferredIpProtocol string `yaml:"preferred_ip_protocol"` // Defaults to "ip6". + Body string `yaml:"body"` } type QueryResponse struct { -- 2.25.1