Skip to content

Commit 3d0ca6c

Browse files
committed
RDBC-940 Zstd-compression data prevents simple store.
1 parent 9eb4049 commit 3d0ca6c

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

ravendb/http/raven_command.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,23 @@ def set_response(self, response: Optional[str], from_cache: bool) -> None:
9797
)
9898

9999
def send(self, session: requests.Session, request: requests.Request) -> requests.Response:
100-
return session.request(
101-
request.method,
102-
url=request.url,
103-
data=request.data,
104-
files=request.files,
105-
cert=session.cert,
106-
headers=request.headers,
107-
)
100+
prepared_request = session.prepare_request(request)
101+
self._remove_zstd_encoding(prepared_request)
102+
return session.send(prepared_request, cert=session.cert)
103+
104+
# https://issues.hibernatingrhinos.com/issue/RDBC-940
105+
# If user has installed module 'zstd' or 'zstandard',
106+
# 'requests' module will automatically add 'zstd' to 'Accept-Encoding' header.
107+
# This causes exceptions. Excluding 'zstd' from the header in this workaround,
108+
# while we keep investigating cause of the issue.
109+
@staticmethod
110+
def _remove_zstd_encoding(request: requests.PreparedRequest) -> None:
111+
accept_encoding = request.headers.get("Accept-Encoding")
112+
113+
if "zstd" in accept_encoding:
114+
encodings = [encoding.strip() for encoding in accept_encoding.split(",") if encoding.strip().lower() != "zstd"]
115+
new_header_value = ", ".join(encodings)
116+
request.headers["Accept-Encoding"] = new_header_value
108117

109118
def set_response_raw(self, response: requests.Response, stream: bytes) -> None:
110119
raise RuntimeError(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name="ravendb",
55
packages=find_packages(exclude=["*.tests.*", "tests", "*.tests", "tests.*"]),
6-
version="7.1.2.post2",
6+
version="7.1.2.post3",
77
long_description_content_type="text/markdown",
88
long_description=open("README_pypi.md").read(),
99
description="Python client for RavenDB NoSQL Database",

0 commit comments

Comments
 (0)