diff --git a/libbeat/kibana/client.go b/libbeat/kibana/client.go index 7d424d38eae9..174ef1113db1 100644 --- a/libbeat/kibana/client.go +++ b/libbeat/kibana/client.go @@ -19,6 +19,7 @@ package kibana import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -181,9 +182,16 @@ func (conn *Connection) Request(method, extraPath string, func (conn *Connection) Send(method, extraPath string, params url.Values, headers http.Header, body io.Reader) (*http.Response, error) { + return conn.SendWithContext(context.Background(), method, extraPath, params, headers, body) +} + +// SendWithContext sends an application/json request to Kibana with appropriate kbn headers and the given context. +func (conn *Connection) SendWithContext(ctx context.Context, method, extraPath string, + params url.Values, headers http.Header, body io.Reader) (*http.Response, error) { + reqURL := addToURL(conn.URL, extraPath, params) - req, err := http.NewRequest(method, reqURL, body) + req, err := http.NewRequestWithContext(ctx, method, reqURL, body) if err != nil { return nil, fmt.Errorf("fail to create the HTTP %s request: %+v", method, err) }