OLD | NEW |
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2016 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 """The request data track. | 5 """The request data track. |
6 | 6 |
7 When executed, parses a JSON dump of DevTools messages. | 7 When executed, parses a JSON dump of DevTools messages. |
8 """ | 8 """ |
9 | 9 |
10 import bisect | 10 import bisect |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 return self.status is not None | 334 return self.status is not None |
335 | 335 |
336 def GetCacheControlDirective(self, directive_name): | 336 def GetCacheControlDirective(self, directive_name): |
337 """Returns the value of a Cache-Control directive, or None.""" | 337 """Returns the value of a Cache-Control directive, or None.""" |
338 cache_control_str = self.GetHTTPResponseHeader('Cache-Control') | 338 cache_control_str = self.GetHTTPResponseHeader('Cache-Control') |
339 if cache_control_str is None: | 339 if cache_control_str is None: |
340 return None | 340 return None |
341 directives = [s.strip() for s in cache_control_str.split(',')] | 341 directives = [s.strip() for s in cache_control_str.split(',')] |
342 for directive in directives: | 342 for directive in directives: |
343 parts = directive.split('=') | 343 parts = directive.split('=') |
344 if len(parts) == 1: | 344 if len(parts) != 2: |
345 continue | 345 continue |
346 (name, value) = parts | 346 (name, value) = parts |
347 if name == directive_name: | 347 if name == directive_name: |
348 return value | 348 return value |
349 return None | 349 return None |
350 | 350 |
351 def MaxAge(self): | 351 def MaxAge(self): |
352 """Returns the max-age of a resource, or -1.""" | 352 """Returns the max-age of a resource, or -1.""" |
353 # TODO(lizeb): Handle the "Expires" header as well. | 353 # TODO(lizeb): Handle the "Expires" header as well. |
354 cache_control = {} | 354 cache_control = {} |
(...skipping 23 matching lines...) Expand all Loading... |
378 request_time and the latest timing event. | 378 request_time and the latest timing event. |
379 """ | 379 """ |
380 # All fields in timing are millis relative to request_time. | 380 # All fields in timing are millis relative to request_time. |
381 return self.timing.LargestOffset() | 381 return self.timing.LargestOffset() |
382 | 382 |
383 def GetRawResponseHeaders(self): | 383 def GetRawResponseHeaders(self): |
384 """Gets the request's raw response headers compatible with | 384 """Gets the request's raw response headers compatible with |
385 net::HttpResponseHeaders's constructor. | 385 net::HttpResponseHeaders's constructor. |
386 """ | 386 """ |
387 assert not self.IsDataRequest() | 387 assert not self.IsDataRequest() |
388 headers = '{} {} {}\x00'.format( | 388 assert self.HasReceivedResponse() |
389 self.protocol.upper(), self.status, self.status_text) | 389 headers = bytes('{} {} {}\x00'.format( |
| 390 self.protocol.upper(), self.status, self.status_text)) |
390 for key in sorted(self.response_headers.keys()): | 391 for key in sorted(self.response_headers.keys()): |
391 headers += '{}: {}\x00'.format(key, self.response_headers[key]) | 392 headers += (bytes(key.encode('latin-1')) + b': ' + |
| 393 bytes(self.response_headers[key].encode('latin-1')) + b'\x00') |
392 return headers | 394 return headers |
393 | 395 |
394 def __eq__(self, o): | 396 def __eq__(self, o): |
395 return self.__dict__ == o.__dict__ | 397 return self.__dict__ == o.__dict__ |
396 | 398 |
397 def __hash__(self): | 399 def __hash__(self): |
398 return hash(self.request_id) | 400 return hash(self.request_id) |
399 | 401 |
400 def __str__(self): | 402 def __str__(self): |
401 return json.dumps(self.ToJsonDict(), sort_keys=True, indent=2) | 403 return json.dumps(self.ToJsonDict(), sort_keys=True, indent=2) |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 | 864 |
863 | 865 |
864 if __name__ == '__main__': | 866 if __name__ == '__main__': |
865 import json | 867 import json |
866 import sys | 868 import sys |
867 events = json.load(open(sys.argv[1], 'r')) | 869 events = json.load(open(sys.argv[1], 'r')) |
868 request_track = RequestTrack(None) | 870 request_track = RequestTrack(None) |
869 for event in events: | 871 for event in events: |
870 event_method = event['method'] | 872 event_method = event['method'] |
871 request_track.Handle(event_method, event) | 873 request_track.Handle(event_method, event) |
OLD | NEW |