Skip to content

Commit

Permalink
Merge #763
Browse files Browse the repository at this point in the history
763: Don't send body for get requests r=alallema a=sanders41

# Pull Request

## Related issue
Fixes #762

## What does this PR do?
- Makes it where the body isn't sent with the request if it is empty.

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Paul Sanders <psanders1@gmail.com>
Co-authored-by: Amélie <alallema@users.noreply.github.com>
  • Loading branch information
3 people committed May 23, 2023
2 parents 5f2a78f + d1faeb4 commit 5d51424
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def send_request(
self.headers["Content-Type"] = content_type
try:
request_path = self.config.url + "/" + path
if isinstance(body, bytes):
if http_method.__name__ == "get":
request = http_method(
request_path,
timeout=self.config.timeout,
headers=self.headers,
)
elif isinstance(body, bytes):
request = http_method(
request_path,
timeout=self.config.timeout,
Expand Down
2 changes: 1 addition & 1 deletion tests/errors/test_api_error_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_meilisearch_api_error_wrong_master_key():
@patch("requests.post")
def test_meilisearch_api_error_no_code(mock_post):
"""Here to test for regressions related to https://github.com/meilisearch/meilisearch-python/issues/305."""

mock_post.configure_mock(__name__="post")
mock_response = requests.models.Response()
mock_response.status_code = 408
mock_post.return_value = mock_response
Expand Down
1 change: 1 addition & 0 deletions tests/errors/test_communication_error_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@patch("requests.post")
def test_meilisearch_communication_error_host(mock_post):
mock_post.configure_mock(__name__="post")
mock_post.side_effect = requests.exceptions.ConnectionError()
client = meilisearch.Client("http://wrongurl:1234", MASTER_KEY)
with pytest.raises(MeilisearchCommunicationError):
Expand Down
1 change: 1 addition & 0 deletions tests/errors/test_timeout_error_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@patch("requests.get")
def test_client_timeout_error(mock_get):
mock_get.configure_mock(__name__="get")
mock_get.side_effect = requests.exceptions.Timeout()
client = meilisearch.Client(BASE_URL, MASTER_KEY, timeout=1)

Expand Down

0 comments on commit 5d51424

Please sign in to comment.