diff --git a/heartbeat/docs/monitors/monitor-http.asciidoc b/heartbeat/docs/monitors/monitor-http.asciidoc index 933a95b68a7a..bc43bc285944 100644 --- a/heartbeat/docs/monitors/monitor-http.asciidoc +++ b/heartbeat/docs/monitors/monitor-http.asciidoc @@ -133,8 +133,8 @@ Example configuration: Under `check.request`, specify these options: -*`method`*:: The HTTP method to use. Valid values are `"HEAD"`, `"GET"`, `"POST"` and -`"OPTIONS"`. +*`method`*:: The HTTP method to use. Valid values are `"HEAD"`, `"GET"`, `"POST"`, `"PUT"`, `"DELETE"`, `"CONNECT"`, +`"TRACE"` and `"OPTIONS"`. *`headers`*:: A dictionary of additional HTTP headers to send. By default heartbeat will set the 'User-Agent' header to identify itself. *`body`*:: Optional request body content. diff --git a/heartbeat/monitors/active/http/config.go b/heartbeat/monitors/active/http/config.go index 157585d968e6..976e4612d876 100644 --- a/heartbeat/monitors/active/http/config.go +++ b/heartbeat/monitors/active/http/config.go @@ -19,6 +19,7 @@ package http import ( "fmt" + "net/http" "net/url" "strings" "time" @@ -137,7 +138,7 @@ func (r *responseConfig) Validate() error { // Validate validates of the requestParameters object is valid or not func (r *requestParameters) Validate() error { switch strings.ToUpper(r.Method) { - case "HEAD", "GET", "POST", "OPTIONS": + case http.MethodOptions, http.MethodHead, http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodConnect, http.MethodTrace: default: return fmt.Errorf("HTTP method '%v' not supported", r.Method) } diff --git a/heartbeat/tests/system/heartbeat.py b/heartbeat/tests/system/heartbeat.py index 85d00b2ba4d4..cea700cb39a7 100644 --- a/heartbeat/tests/system/heartbeat.py +++ b/heartbeat/tests/system/heartbeat.py @@ -12,14 +12,15 @@ class BaseTest(TestCase): def setUpClass(self): self.beat_name = "heartbeat" self.beat_path = os.path.abspath( - os.path.join(os.path.dirname(__file__), "../../")) + os.path.join(os.path.dirname(__file__), "../../") + ) super(BaseTest, self).setUpClass() def start_server(self, content, status_code, **kwargs): class HTTPHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): self.send_response(status_code) - self.send_header('Content-Type', 'application/json') + self.send_header("Content-Type", "application/json") self.end_headers() if "write_delay" in kwargs: sleep(float(kwargs["write_delay"])) @@ -30,16 +31,19 @@ def do_GET(self): class HTTPHandlerEnabledOPTIONS(HTTPHandler): def do_OPTIONS(self): self.send_response(status_code) - self.send_header('Access-Control-Allow-Credentials', 'true') - self.send_header('Access-Control-Allow-Origin', '*') - self.send_header('Access-Control-Allow-Methods', 'HEAD, GET, POST, OPTIONS') + self.send_header("Access-Control-Allow-Credentials", "true") + self.send_header("Access-Control-Allow-Origin", "*") + self.send_header( + "Access-Control-Allow-Methods", + "HEAD, GET, POST, OPTIONS, PUT, DELETE, CONNECT, TRACE", + ) self.end_headers() # initialize http server based on if it needs to support OPTIONS method - server = http.server.HTTPServer(('localhost', 0), HTTPHandler) + server = http.server.HTTPServer(("localhost", 0), HTTPHandler) # setup enable_options_method as False if it's not set if kwargs.get("enable_options_method", False): - server = http.server.HTTPServer(('localhost', 0), HTTPHandlerEnabledOPTIONS) + server = http.server.HTTPServer(("localhost", 0), HTTPHandlerEnabledOPTIONS) thread = threading.Thread(target=server.serve_forever) thread.start() @@ -54,7 +58,11 @@ def http_cfg(id, url): schedule: "@every 1s" timeout: 3s urls: ["{url}"] - """[1:-1].format(id=id, url=url) + """[ + 1:-1 + ].format( + id=id, url=url + ) @staticmethod def tcp_cfg(*hosts): @@ -64,13 +72,17 @@ def tcp_cfg(*hosts): schedule: "@every 1s" timeout: 3s hosts: [{host_str}] - """[1:-1].format(host_str=host_str) + """[ + 1:-1 + ].format( + host_str=host_str + ) def last_output_line(self): return self.read_output()[-1] def write_dyn_config(self, filename, cfg): - with open(self.monitors_dir() + filename, 'w') as f: + with open(self.monitors_dir() + filename, "w") as f: f.write(cfg) def monitors_dir(self):