Added support for posting a body of content (#86)
authorAndrew Hemming <drewhemm@users.noreply.github.com>
Wed, 7 Dec 2016 15:13:15 +0000 (15:13 +0000)
committerBrian Brazil <brian-brazil@users.noreply.github.com>
Wed, 7 Dec 2016 15:13:15 +0000 (15:13 +0000)
README.md
http.go
main.go

index 704fcdb451b8c86743e9f56f36191a18b1ed984e..b4b9591e9ae11503b8a176d3062f0c31333386f2 100644 (file)
--- 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 5bf947327ac9d35ee62ada5b710ebe7ada2763ec..8993f92276c9282e356bc851552e8cde06d7bf90 100644 (file)
--- 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 e5a0523666dab5690aff296dc2b5e4fceb9e1912..d6901ed128a6d1fd7959662bec772cad894a1c99 100644 (file)
--- 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 {