Skip to content

Commit 74664a0

Browse files
committed
RDBC-940 Add missing stream argument
1 parent e25ea99 commit 74664a0

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

ravendb/documents/commands/stream.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ravendb.http.server_node import ServerNode
1010
from ravendb.http.raven_command import RavenCommand, RavenCommandResponseType
1111
from ravendb.json.metadata_as_dictionary import MetadataAsDictionary
12-
12+
from ravendb.util.request_utils import RequestUtils
1313

1414
_T = TypeVar("_T")
1515

@@ -51,6 +51,11 @@ def process_response(self, cache: HttpCache, response: requests.Response, url) -
5151
except Exception as e:
5252
raise RuntimeError("Unable to process stream response", e)
5353

54+
def send(self, session: requests.Session, request: requests.Request) -> requests.Response:
55+
prepared_request = session.prepare_request(request)
56+
RequestUtils.remove_zstd_encoding(prepared_request)
57+
return session.send(prepared_request, cert=session.cert, stream=True)
58+
5459
def is_read_request(self) -> bool:
5560
return True
5661

@@ -85,5 +90,10 @@ def process_response(self, cache: HttpCache, response: requests.Response, url) -
8590
except Exception as e:
8691
raise RuntimeError("Unable to process stream response: " + e.args[0], e)
8792

93+
def send(self, session: requests.Session, request: requests.Request) -> requests.Response:
94+
prepared_request = session.prepare_request(request)
95+
RequestUtils.remove_zstd_encoding(prepared_request)
96+
return session.send(prepared_request, cert=session.cert, stream=True)
97+
8898
def is_read_request(self) -> bool:
8999
return True

ravendb/http/raven_command.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ravendb.http.http_cache import HttpCache
1313
from ravendb.http.misc import ResponseDisposeHandling
1414
from ravendb.http.server_node import ServerNode
15+
from ravendb.util.request_utils import RequestUtils
1516

1617

1718
class RavenCommandResponseType(Enum):
@@ -98,25 +99,9 @@ def set_response(self, response: Optional[str], from_cache: bool) -> None:
9899

99100
def send(self, session: requests.Session, request: requests.Request) -> requests.Response:
100101
prepared_request = session.prepare_request(request)
101-
self._remove_zstd_encoding(prepared_request)
102+
RequestUtils.remove_zstd_encoding(prepared_request)
102103
return session.send(prepared_request, cert=session.cert)
103104

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 = [
115-
encoding.strip() for encoding in accept_encoding.split(",") if encoding.strip().lower() != "zstd"
116-
]
117-
new_header_value = ", ".join(encodings)
118-
request.headers["Accept-Encoding"] = new_header_value
119-
120105
def set_response_raw(self, response: requests.Response, stream: bytes) -> None:
121106
raise RuntimeError(
122107
f"When {self.response_type} is set to Raw then please override this method to handle the response "

ravendb/util/request_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import requests
2+
3+
4+
class RequestUtils:
5+
6+
# https://issues.hibernatingrhinos.com/issue/RDBC-940
7+
# If user has installed module 'zstd' or 'zstandard',
8+
# 'requests' module will automatically add 'zstd' to 'Accept-Encoding' header.
9+
# This causes exceptions. Excluding 'zstd' from the header in this workaround,
10+
# while we keep investigating cause of the issue.
11+
@staticmethod
12+
def remove_zstd_encoding(request: requests.PreparedRequest) -> None:
13+
accept_encoding = request.headers.get("Accept-Encoding")
14+
15+
if "zstd" in accept_encoding:
16+
encodings = [
17+
encoding.strip() for encoding in accept_encoding.split(",") if encoding.strip().lower() != "zstd"
18+
]
19+
new_header_value = ", ".join(encodings)
20+
request.headers["Accept-Encoding"] = new_header_value

0 commit comments

Comments
 (0)