Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tools/findit/common/http_client_local.py

Issue 538383002: [Findit] Make Findit more robust. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Workaround python bug. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """ 5 """
6 A http client with support for https connections with certificate verification. 6 A http client with support for https connections with certificate verification.
7 7
8 The verification is based on http://tools.ietf.org/html/rfc6125#section-6.4.3 8 The verification is based on http://tools.ietf.org/html/rfc6125#section-6.4.3
9 and the code is from Lib/ssl.py in python3: 9 and the code is from Lib/ssl.py in python3:
10 http://hg.python.org/cpython/file/4dac45f88d45/Lib/ssl.py 10 http://hg.python.org/cpython/file/4dac45f88d45/Lib/ssl.py
11 11
12 One use case is to download Chromium DEPS file in a secure way: 12 One use case is to download Chromium DEPS file in a secure way:
13 https://src.chromium.org/chrome/trunk/src/DEPS 13 https://src.chromium.org/chrome/trunk/src/DEPS
14 14
15 Notice: python 2.7 or newer is required. 15 Notice: python 2.7 or newer is required.
16 """ 16 """
17 17
18 import cookielib 18 import cookielib
19 import httplib 19 import httplib
20 import os 20 import os
21 import re 21 import re
22 import socket 22 import socket
23 import ssl 23 import ssl
24 import time
24 import urllib 25 import urllib
25 import urllib2 26 import urllib2
26 27
27 import http_client 28 import http_client
28 29
29 30
30 _SCRIPT_DIR = os.path.dirname(__file__) 31 _SCRIPT_DIR = os.path.dirname(__file__)
31 _TRUSTED_ROOT_CERTS = os.path.join(_SCRIPT_DIR, 'cacert.pem') 32 _TRUSTED_ROOT_CERTS = os.path.join(_SCRIPT_DIR, 'cacert.pem')
32 33
33 34
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 status_code = e.code 219 status_code = e.code
219 content = None 220 content = None
220 221
221 return status_code, content 222 return status_code, content
222 223
223 224
224 class HttpClientLocal(http_client.HttpClient): 225 class HttpClientLocal(http_client.HttpClient):
225 """This http client is used locally in a workstation, GCE VMs, etc.""" 226 """This http client is used locally in a workstation, GCE VMs, etc."""
226 227
227 @staticmethod 228 @staticmethod
228 def Get(url, params={}, timeout=None): 229 def Get(url, params={}, timeout=60, retries=5, retry_interval=0.5,
230 retry_if_not=None):
229 if params: 231 if params:
230 url = '%s?%s' % (url, urllib.urlencode(params)) 232 url = '%s?%s' % (url, urllib.urlencode(params))
231 return _SendRequest(url, timeout=timeout) 233
234 count = 0
235 while True:
236 count += 1
237
238 status_code, content = _SendRequest(url, timeout=timeout)
239 if status_code == 200:
240 return status_code, content
241 if retry_if_not and status_code == retry_if_not:
242 return status_code, content
243
244 if count < retries:
245 time.sleep(retry_interval)
246 else:
247 return status_code, content
248
249 # Should never be reached.
250 return status_code, content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698