monitoring icon indicating copy to clipboard operation
monitoring copied to clipboard

HTTP test method refactor ?

Open brunobord opened this issue 14 years ago • 3 comments

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.

brunobord avatar Oct 24 '11 19:10 brunobord

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.

sebastien avatar Oct 24 '11 21:10 sebastien

and what about the first question? the fact that, asking for a POST leads you to make a "GET" request?

brunobord avatar Oct 25 '11 07:10 brunobord

This is a bug, it should be fixed.

sebastien avatar Oct 25 '11 13:10 sebastien