-
Notifications
You must be signed in to change notification settings - Fork 200
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
SG-35712 Prevent flaky disconnection when uploading thumbnails on publish #368
base: master
Are you sure you want to change the base?
Changes from all commits
515b208
570acba
87cac36
2fbb8eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4151,16 +4151,16 @@ def _upload_data_to_storage(self, data, content_type, size, storage_url): | |
:returns: upload url. | ||
:rtype: str | ||
""" | ||
opener = self._build_opener(urllib.request.HTTPHandler) | ||
|
||
request = urllib.request.Request(storage_url, data=data) | ||
request.add_header("Content-Type", content_type) | ||
request.add_header("Content-Length", size) | ||
request.get_method = lambda: "PUT" | ||
|
||
attempt = 1 | ||
while attempt <= self.MAX_ATTEMPTS: | ||
try: | ||
opener = self._build_opener(urllib.request.HTTPHandler) | ||
|
||
request = urllib.request.Request(storage_url, data=data) | ||
request.add_header("Content-Type", content_type) | ||
request.add_header("Content-Length", size) | ||
request.get_method = lambda: "PUT" | ||
result = self._make_upload_request(request, opener) | ||
|
||
LOG.debug("Completed request to %s" % request.get_method()) | ||
|
@@ -4267,12 +4267,12 @@ def _send_form(self, url, params): | |
|
||
params.update(self._auth_params()) | ||
|
||
opener = self._build_opener(FormPostHandler) | ||
|
||
attempt = 1 | ||
while attempt <= self.MAX_ATTEMPTS: | ||
# Perform the request | ||
try: | ||
opener = self._build_opener(FormPostHandler) | ||
resp = opener.open(url, params) | ||
result = resp.read() | ||
# response headers are in str(resp.info()).splitlines() | ||
|
@@ -4309,11 +4309,11 @@ def __init__(self, *args, **kwargs): | |
""" | ||
# Pop that argument, | ||
self.__ca_certs = kwargs.pop("ca_certs") | ||
http_client.HTTPConnection.__init__(self, *args, **kwargs) | ||
super().__init__(self, *args, **kwargs) | ||
|
||
def connect(self): | ||
"Connect to a host on a given (SSL) port." | ||
http_client.HTTPConnection.connect(self) | ||
super().connect(self) | ||
# Now that the regular HTTP socket has been created, wrap it with our SSL certs. | ||
if six.PY38: | ||
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | ||
|
@@ -4330,13 +4330,13 @@ def connect(self): | |
) | ||
|
||
|
||
class CACertsHTTPSHandler(urllib.request.HTTPSHandler): | ||
class CACertsHTTPSHandler(urllib.request.HTTPHandler): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a clear answer for this. I was a trial/error change that made sense to me according to keep consistency on naming. Also, we're using SSL with TLS. |
||
""" | ||
Handler that ensures https connections are created with the custom CA certs. | ||
""" | ||
|
||
def __init__(self, cacerts): | ||
urllib.request.HTTPSHandler.__init__(self) | ||
super().__init__(self) | ||
self.__ca_certs = cacerts | ||
|
||
def https_open(self, req): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side question: why don't we use httplib2 for those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to answer this. This line was moved from outside the retry block, so in case it fails, the retry can start a new connection. I don't know the details of the original design.