-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not send body in GET requests #306
Conversation
if "files" in kwargs: | ||
kwargs.setdefault("data", payload) | ||
|
||
else: | ||
kwargs.setdefault("data", utils.json_dumps(payload)) | ||
kwargs["headers"].setdefault("Content-Type", "application/json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kwargs["headers"].setdefault("Content-Type", "application/json") | |
kwargs["headers"].setdefault("Content-Type", "application/json") | |
if method.lower() in ("get", "head") and kwargs.get("data"): | |
raise KintoException("GET requests are not allowed to have a body!") |
Because in the bug we found, data
is not specified, but we have payload = payload or {}
and kwargs.setdefault("data", payload)
By moving it down here, we cover all cases.
with pytest.raises(KintoException) as err: | ||
session.request("GET", "/", data={"foo": "bar"}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also add a test that fails with current master, which is:
def test_get_does_not_send_body(session_setup: Tuple[MagicMock, Session]): | |
requests_mock, _ = session_setup | |
response = get_200() | |
requests_mock.request.return_value = response | |
session = Session("https://example.org", timeout=4) | |
assert session.auth is None | |
session.request("GET", "/test") | |
requests_mock.request.assert_called_with( | |
"GET", | |
"https://example.org/test", | |
timeout=4, | |
headers=requests_mock.request.headers, | |
) | |
No description provided.