diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_bigger_block_size_http_adapters.py b/sdk/core/azure-core/azure/core/pipeline/transport/_bigger_block_size_http_adapters.py new file mode 100644 index 000000000000..0bb8d9d0cc50 --- /dev/null +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_bigger_block_size_http_adapters.py @@ -0,0 +1,45 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +import sys +from requests.adapters import HTTPAdapter + + +class BiggerBlockSizeHTTPAdapter(HTTPAdapter): + def get_connection(self, url, proxies=None): + """Returns a urllib3 connection for the given URL. This should not be + called from user code, and is only exposed for use when subclassing the + :class:`HTTPAdapter `. + + :param url: The URL to connect to. + :param proxies: (optional) A Requests-style dictionary of proxies used on this request. + :rtype: urllib3.ConnectionPool + """ + conn = super(BiggerBlockSizeHTTPAdapter, self).get_connection(url, proxies) + system_version = tuple(sys.version_info)[:3] + if system_version[:2] >= (3, 7): + conn.conn_kw = {"blocksize": 32768} + return conn diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py b/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py index ea0e7b0e4c9c..987222eceaae 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py @@ -43,6 +43,7 @@ HttpResponse, _HttpResponseBase ) +from ._bigger_block_size_http_adapters import BiggerBlockSizeHTTPAdapter PipelineType = TypeVar("PipelineType") @@ -213,7 +214,7 @@ def _init_session(self, session): """ session.trust_env = self._use_env_settings disable_retries = Retry(total=False, redirect=False, raise_on_status=False) - adapter = requests.adapters.HTTPAdapter(max_retries=disable_retries) + adapter = BiggerBlockSizeHTTPAdapter(max_retries=disable_retries) for p in self._protocols: session.mount(p, adapter)