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

Side by Side Diff: tools/chrome_proxy/common/chrome_proxy_metrics.py

Issue 1151753003: Integration test for Chrome-Proxy: pass-through directive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@loFiSnackbar
Patch Set: rebase Created 5 years, 7 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
« no previous file with comments | « no previous file | tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 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 import logging 5 import logging
6 import time 6 import time
7 7
8 from common import network_metrics 8 from common import network_metrics
9 from telemetry.page import page_test 9 from telemetry.page import page_test
10 from telemetry.value import scalar 10 from telemetry.value import scalar
(...skipping 20 matching lines...) Expand all
31 if resp.status == 304 or resp.served_from_cache: 31 if resp.status == 304 or resp.served_from_cache:
32 return False 32 return False
33 # Ignore invalid responses that don't have any header. Log a warning. 33 # Ignore invalid responses that don't have any header. Log a warning.
34 if not resp.headers: 34 if not resp.headers:
35 logging.warning('response for %s does not any have header ' 35 logging.warning('response for %s does not any have header '
36 '(refer=%s, status=%s)', 36 '(refer=%s, status=%s)',
37 resp.url, resp.GetHeader('Referer'), resp.status) 37 resp.url, resp.GetHeader('Referer'), resp.status)
38 return False 38 return False
39 return True 39 return True
40 40
41 def HasResponseHeader(self, key, value):
42 response_header = self.response.GetHeader(key)
43 if not response_header:
44 return False
45 values = [v.strip() for v in response_header.split(',')]
46 return any(v == value for v in values)
47
48 def HasRequestHeader(self, key, value):
49 if key not in self.response.request_headers:
50 return False
51 request_header = self.response.request_headers[key]
52 values = [v.strip() for v in request_header.split(',')]
53 return any(v == value for v in values)
54
41 def HasChromeProxyViaHeader(self): 55 def HasChromeProxyViaHeader(self):
42 via_header = self.response.GetHeader('Via') 56 via_header = self.response.GetHeader('Via')
43 if not via_header: 57 if not via_header:
44 return False 58 return False
45 vias = [v.strip(' ') for v in via_header.split(',')] 59 vias = [v.strip(' ') for v in via_header.split(',')]
46 # The Via header is valid if it has a 4-character version prefix followed by 60 # The Via header is valid if it has a 4-character version prefix followed by
47 # the proxy name, for example, "1.1 Chrome-Compression-Proxy". 61 # the proxy name, for example, "1.1 Chrome-Compression-Proxy".
48 return any(v[4:] == CHROME_PROXY_VIA_HEADER for v in vias) 62 return any(v[4:] == CHROME_PROXY_VIA_HEADER for v in vias)
49 63
50 def HasExtraViaHeader(self, extra_header): 64 def HasExtraViaHeader(self, extra_header):
51 via_header = self.response.GetHeader('Via') 65 return self.HasResponseHeader('Via', extra_header)
52 if not via_header:
53 return False
54 vias = [v.strip(' ') for v in via_header.split(',')]
55 return any(v == extra_header for v in vias)
56 66
57 def IsValidByViaHeader(self): 67 def IsValidByViaHeader(self):
58 return (not self.ShouldHaveChromeProxyViaHeader() or 68 return (not self.ShouldHaveChromeProxyViaHeader() or
59 self.HasChromeProxyViaHeader()) 69 self.HasChromeProxyViaHeader())
60 70
61 def GetChromeProxyClientType(self): 71 def GetChromeProxyClientType(self):
62 """Get the client type directive from the Chrome-Proxy request header. 72 """Get the client type directive from the Chrome-Proxy request header.
63 73
64 Returns: 74 Returns:
65 The client type directive from the Chrome-Proxy request header for the 75 The client type directive from the Chrome-Proxy request header for the
66 request that lead to this response. For example, if the request header 76 request that lead to this response. For example, if the request header
67 "Chrome-Proxy: c=android" is present, then this method would return 77 "Chrome-Proxy: c=android" is present, then this method would return
68 "android". Returns None if no client type directive is present. 78 "android". Returns None if no client type directive is present.
69 """ 79 """
70 if 'Chrome-Proxy' not in self.response.request_headers: 80 if 'Chrome-Proxy' not in self.response.request_headers:
71 return None 81 return None
72 82
73 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] 83 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy']
74 values = [v.strip() for v in chrome_proxy_request_header.split(',')] 84 values = [v.strip() for v in chrome_proxy_request_header.split(',')]
75 for value in values: 85 for value in values:
76 kvp = value.split('=', 1) 86 kvp = value.split('=', 1)
77 if len(kvp) == 2 and kvp[0].strip() == 'c': 87 if len(kvp) == 2 and kvp[0].strip() == 'c':
78 return kvp[1].strip() 88 return kvp[1].strip()
79 return None 89 return None
80 90
81 def HasChromeProxyLoFiRequest(self): 91 def HasChromeProxyLoFiRequest(self):
82 if 'Chrome-Proxy' not in self.response.request_headers: 92 return self.HasRequestHeader('Chrome-Proxy', "q=low")
83 return False
84 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy']
85 values = [v.strip() for v in chrome_proxy_request_header.split(',')]
86 return any(v == "q=low" for v in values)
87 93
88 def HasChromeProxyLoFiResponse(self): 94 def HasChromeProxyLoFiResponse(self):
89 chrome_proxy_response_header = self.response.GetHeader('Chrome-Proxy') 95 return self.HasResponseHeader('Chrome-Proxy', "q=low")
90 if not chrome_proxy_response_header: 96
91 return False 97 def HasChromeProxyPassThroughRequest(self):
92 values = [v.strip() for v in chrome_proxy_response_header.split(',')] 98 return self.HasRequestHeader('Chrome-Proxy', "pass-through")
93 return any(v == "q=low" for v in values)
OLDNEW
« no previous file with comments | « no previous file | tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698