monitoring
monitoring copied to clipboard
HTTP test method refactor ?
Hi there,
I was a little bit puzzled by the HTTP constructor:
https://github.com/sebastien/watchdog/blob/master/Sources/watchdog.py#L854
a - if you use a "POST" or a "GET" argument, the method used is "GET", whatever it is. b - I've added a HEAD argument on my latest pull request, according to the current practise, but I wonder if this constructor could be simplified. something like:
def __init__(self, url, method=None, timeout=Time.s(10), freq=Time.m(1), fail=(), success=()):
Rule.__init__(self, freq, fail, success)
if not method:
method = "GET"
if method not in ('GET', 'POST', 'HEAD'):
raise Exception()
# .. all the rest is the same...
if url.startswith("http://"):
url = url[7:]
server, uri = url.split("/", 1)
# ...
Of course, this would be annoying, because it's not retro-compatible with the current API, that's the reason why I didn't open a pull request, and I wonder if this refactor is possible or not.
The reason is that you can do HTTP(GET="/my/url"), etc, which is more declarative than HTTP(method="GET",url="/my/url"). Your original patch was very good.
and what about the first question? the fact that, asking for a POST leads you to make a "GET" request?
This is a bug, it should be fixed.