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

Unified Diff: tools/android/loading/request_track.py

Issue 1707173003: tools/android/loading Add 'redirect' and 'ping' content types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/android/loading/model_graph.py ('k') | tools/android/loading/request_track_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/request_track.py
diff --git a/tools/android/loading/request_track.py b/tools/android/loading/request_track.py
index 2c94703dd035a9e3c93df8749c00acf568d640f9..b1f08d33ab2ee9fb647ae479bfb8d943818ceb99 100644
--- a/tools/android/loading/request_track.py
+++ b/tools/android/loading/request_track.py
@@ -179,19 +179,36 @@ class Request(object):
result.timing = TimingFromDict({'requestTime': result.timestamp})
return result
+ """Gets the value of a HTTP response header.
Benoit L 2016/02/18 11:01:27 docstrings go below the function name, not above.
+
+ Does a case-insensitive search for the header name in the HTTP response
+ headers, in order to support servers that use a wrong capitalization.
+ """
+ def GetHTTPResponseHeader(self, header_name):
+ small_caps_name = header_name.lower()
Benoit L 2016/02/18 11:01:27 nit: lower_case_name?
+ result = None
+ for name, value in self.response_headers.iteritems():
+ if name.lower() == small_caps_name:
+ result = value
+ break
+ return result
+
def GetContentType(self):
"""Returns the content type, or None."""
+ # Check for redirects. Use the "Location" header, because the HTTP status is
+ # not reliable.
+ if self.GetHTTPResponseHeader('Location') is not None:
+ return 'redirect'
+
+ # Check if the response is empty.
+ if (self.GetHTTPResponseHeader('Content-Length') == '0' or
+ self.status == 204):
+ return 'ping'
+
if self.mime_type:
return self.mime_type
- # Case-insensitive search because servers sometimes use a wrong
- # capitalization.
- content_type = None
- for header, value in self.response_headers.iteritems():
- if header.lower() == 'content-type':
- content_type = value
- break
-
+ content_type = self.GetHTTPResponseHeader('Content-Type')
if not content_type or ';' not in content_type:
return content_type
else:
@@ -207,14 +224,7 @@ class Request(object):
if not self.response_headers:
return -1
- # Case-insensitive search because servers sometimes use a wrong
- # capitalization.
- cache_control_str = None
- for header, value in self.response_headers.iteritems():
- if header.lower() == 'cache-control':
- cache_control_str = value
- break
-
+ cache_control_str = self.GetHTTPResponseHeader('Cache-Control')
if cache_control_str is not None:
directives = [s.strip() for s in cache_control_str.split(',')]
for directive in directives:
« no previous file with comments | « tools/android/loading/model_graph.py ('k') | tools/android/loading/request_track_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698