Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config the default blocksize to 32k for Python 3.7+ #14442

Merged
merged 18 commits into from
Nov 7, 2020
Original file line number Diff line number Diff line change
@@ -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 <requests.adapters.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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
HttpResponse,
_HttpResponseBase
)
from ._bigger_block_size_http_adapters import BiggerBlockSizeHTTPAdapter

PipelineType = TypeVar("PipelineType")

Expand Down Expand Up @@ -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)

Expand Down