HTTP test method refactor ? #7

Open
brunobord opened this Issue Oct 24, 2011 · 3 comments

2 participants

@brunobord

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.

@sebastien
Owner

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 sebastien closed this Oct 24, 2011
@brunobord

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

@sebastien sebastien reopened this Oct 25, 2011
@sebastien
Owner

This is a bug, it should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment