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

Side by Side Diff: tools/findit/https.py

Issue 465403004: [Findit] Support sending cookies for http requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « tools/findit/crash_utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
aarya 2014/08/15 05:29:23 Please rename this file to connection_handler or h
stgao 2014/08/15 06:49:49 This is more than connection_handler or http_handl
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 Provides a utility function for https connections with certificate verification. 5 Provides a utility function for https connections with certificate verification.
6 6
7 The verification is based on http://tools.ietf.org/html/rfc6125#section-6.4.3 7 The verification is based on http://tools.ietf.org/html/rfc6125#section-6.4.3
8 and the code is from Lib/ssl.py in python3: 8 and the code is from Lib/ssl.py in python3:
9 http://hg.python.org/cpython/file/4dac45f88d45/Lib/ssl.py 9 http://hg.python.org/cpython/file/4dac45f88d45/Lib/ssl.py
10 10
11 One use case is to download Chromium DEPS file in a secure way: 11 One use case is to download Chromium DEPS file in a secure way:
12 https://src.chromium.org/chrome/trunk/src/DEPS 12 https://src.chromium.org/chrome/trunk/src/DEPS
13 13
14 Notice: python 2.7 or newer is required. 14 Notice: python 2.7 or newer is required.
15 """ 15 """
16 16
17 import cookielib
17 import httplib 18 import httplib
18 import os 19 import os
19 import re 20 import re
20 import socket 21 import socket
21 import ssl 22 import ssl
22 import urllib2 23 import urllib2
23 24
24 25
25 _SCRIPT_DIR = os.path.dirname(__file__) 26 _SCRIPT_DIR = os.path.dirname(__file__)
26 _TRUSTED_ROOT_CERTS = os.path.join(_SCRIPT_DIR, 'cacert.pem') 27 _TRUSTED_ROOT_CERTS = os.path.join(_SCRIPT_DIR, 'cacert.pem')
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 Returns: 181 Returns:
181 A string that is the response from the server. 182 A string that is the response from the server.
182 183
183 Raises: 184 Raises:
184 ValueError: Unexpected value is received during certificate verification. 185 ValueError: Unexpected value is received during certificate verification.
185 CertificateError: Certificate verification fails. 186 CertificateError: Certificate verification fails.
186 """ 187 """
187 if not https_url or not https_url.startswith('https://'): 188 if not https_url or not https_url.startswith('https://'):
188 raise ValueError('Not a https request for url %s.' % str(https_url)) 189 raise ValueError('Not a https request for url %s.' % str(https_url))
189 190
190 url_opener = urllib2.build_opener(HTTPSHandler) 191 handlers = [HTTPSHandler()]
192 cookie_file = os.environ.get('COOKIE_FILE')
193 if cookie_file and os.path.exists(cookie_file):
194 handlers.append(
195 urllib2.HTTPCookieProcessor(cookielib.MozillaCookieJar(cookie_file)))
196
197 url_opener = urllib2.build_opener(*handlers)
191 return url_opener.open(https_url).read() 198 return url_opener.open(https_url).read()
192 199
193 200
194 if __name__ == '__main__': 201 if __name__ == '__main__':
aarya 2014/08/15 05:29:23 Please remove this test __main__ code.
stgao 2014/08/15 06:49:49 What's the reason to remove this code? It is for t
195 print SendRequest('https://src.chromium.org/chrome/trunk/src/DEPS') 202 print SendRequest('https://src.chromium.org/chrome/trunk/src/DEPS')
OLDNEW
« no previous file with comments | « tools/findit/crash_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698