sebastien/watchdog — Issue #7: HTTP test method refactor ?
Author: brunobord
Created: 2011-10-24 19:29:39+00:00
State: open

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.