OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 import httplib | 5 import httplib |
6 import json | 6 import json |
7 import urllib | 7 import urllib |
8 | 8 |
9 from dashboard.common import utils | 9 from dashboard.common import utils |
10 | 10 |
11 | 11 |
| 12 _VULNERABILITY_PREFIX = ")]}'\n" |
| 13 |
| 14 |
12 def RequestJson(*args, **kwargs): | 15 def RequestJson(*args, **kwargs): |
13 """Fetch a URL and JSON-decode the response. | 16 """Fetch a URL and JSON-decode the response. |
14 | 17 |
15 See the documentation for Request() for details | 18 See the documentation for Request() for details |
16 about the arguments and exceptions. | 19 about the arguments and exceptions. |
17 """ | 20 """ |
18 return json.loads(Request(*args, **kwargs)) | 21 content = Request(*args, **kwargs) |
| 22 if content.startswith(_VULNERABILITY_PREFIX): |
| 23 content = content[len(_VULNERABILITY_PREFIX):] |
| 24 return json.loads(content) |
19 | 25 |
20 | 26 |
21 def Request(url, method='GET', body=None, **parameters): | 27 def Request(url, method='GET', body=None, **parameters): |
22 """Fetch a URL while authenticated as the service account. | 28 """Fetch a URL while authenticated as the service account. |
23 | 29 |
24 Args: | 30 Args: |
25 method: The HTTP request method. E.g. 'GET', 'POST', 'PUT'. | 31 method: The HTTP request method. E.g. 'GET', 'POST', 'PUT'. |
26 body: The request body as a Python object. It will be JSON-encoded. | 32 body: The request body as a Python object. It will be JSON-encoded. |
27 parameters: Parameters to be encoded in the URL query string. | 33 parameters: Parameters to be encoded in the URL query string. |
28 | 34 |
(...skipping 28 matching lines...) Expand all Loading... |
57 | 63 |
58 def _RequestAndProcessHttpErrors(*args, **kwargs): | 64 def _RequestAndProcessHttpErrors(*args, **kwargs): |
59 """Requests a URL, converting HTTP errors to Python exceptions.""" | 65 """Requests a URL, converting HTTP errors to Python exceptions.""" |
60 http = utils.ServiceAccountHttp(timeout=10) | 66 http = utils.ServiceAccountHttp(timeout=10) |
61 response, content = http.request(*args, **kwargs) | 67 response, content = http.request(*args, **kwargs) |
62 if not response['status'].startswith('2'): | 68 if not response['status'].startswith('2'): |
63 raise httplib.HTTPException( | 69 raise httplib.HTTPException( |
64 'HTTP status code %s: %s' % (response['status'], content)) | 70 'HTTP status code %s: %s' % (response['status'], content)) |
65 | 71 |
66 return content | 72 return content |
OLD | NEW |