Commit 04681719 authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Vincent A

browser: better guess POST method with empty data in build_request

Passing data='' or json={} to browser methods like open() or build_request()
used to make a GET, but this is incorrect.

We can simply check the non-None of one of those params.
If a Request parameter is used though, it's more implicit, because we cannot
guess what was the intention, we can't easily distinguish the default value from
an intentionally empty value

    Request().data == []
    Request().json is None
parent e22dd9bf
......@@ -426,7 +426,14 @@ class Browser(object):
# guess method
if req.method is None:
if req.data or req.json:
# 'data' and 'json' (even if empty) are (always?) passed to build_request
# and None is their default. For a Request object, the defaults are different.
# Request.json is None and Request.data == [] by default.
# Could they break unexpectedly?
if (
req.data or kwargs.get('data') is not None
or req.json or kwargs.get('json') is not None
):
req.method = 'POST'
else:
req.method = 'GET'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment