Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def send_request(
) -> Any:
if content_type:
self.headers["Content-Type"] = content_type
else:
self.headers.pop("Content-Type", None)
Comment thread
Strift marked this conversation as resolved.
try:
request_path = self.config.url + "/" + path
if http_method.__name__ == "get":
Expand Down Expand Up @@ -162,6 +164,8 @@ def post_stream(
"""
if content_type:
self.headers["Content-Type"] = content_type
else:
self.headers.pop("Content-Type", None)
try:
request_path = self.config.url + "/" + path

Expand Down
15 changes: 15 additions & 0 deletions tests/client/test_http_requests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import requests

from meilisearch._httprequests import HttpRequests
from meilisearch.config import Config
from meilisearch.version import qualified_version
Expand Down Expand Up @@ -28,3 +30,16 @@ def test_get_headers_with_multiple_user_agent():
http.headers["User-Agent"]
== qualified_version() + ";Meilisearch Package1 (v1.1.1);Meilisearch Package2 (v2.2.2)"
)


def test_reset_content_type_header():
"""Tests that the content type header is reset when no content type is provided."""
config = Config(BASE_URL, MASTER_KEY, timeout=None)
http = HttpRequests(config=config)

http.headers["Content-Type"] = "application/json"
assert http.headers["Content-Type"] == "application/json"

http.send_request(http_method=requests.get, path="health")

assert "Content-Type" not in http.headers