Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api v1 updates #8

Merged
merged 2 commits into from
Jul 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ page in HarParser.pages is a HarPage object::
print har_parser.browser
# {u'name': u'Firefox', u'version': u'25.0.1'}

print har_parser.hostname
# 'humanssuck.net'

for page in har_parser.pages:
assert isinstance(page, HarPage, None)
# returns True for each
Expand All @@ -69,6 +72,10 @@ file (see example above) with `har_data=har_data`::
with open('har_data.har', 'r') as f:
har_page = HarPage('page_3', har_data=json.loads(f.read()))

### GET BASIC INFO
har_page.hostname
# 'humanssuck.net'

### WORK WITH LOAD TIMES (all load times are in ms) ###

# Get image load time in milliseconds as rendered by the browser
Expand Down
13 changes: 13 additions & 0 deletions haralyzer/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def version(self):
def creator(self):
return self.har_data['creator']

@cached_property
def hostname(self):
return self.pages[0].hostname


class MultiHarParser(object):
"""
Expand Down Expand Up @@ -461,6 +465,15 @@ def get_total_size(self, entries):

# BEGIN PROPERTIES #

@cached_property
def hostname(self):
"""
Hostname of the initial request
"""
for header in self.entries[0]['request']['headers']:
if header['name'] == 'Host':
return header['value']

@cached_property
def entries(self):
page_entries = []
Expand Down
9 changes: 9 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ def test_time_to_first_byte(har_data):
assert page.time_to_first_byte == 153


def test_hostname(har_data):
"""
Makes sure that the correct hostname is returned.
"""
init_data = har_data('humanssuck.net.har')
page = HarPage(PAGE_ID, har_data=init_data)
assert page.hostname == 'humanssuck.net'


def _correct_file_type(entry, file_types):
for header in entry['response']['headers']:
if header['name'] == 'Content-Type':
Expand Down
1 change: 1 addition & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_init(har_data):
assert har_parser.browser == {'name': 'Firefox', 'version': '25.0.1'}
assert har_parser.version == '1.1'
assert har_parser.creator == {'name': 'Firebug', 'version': '1.12'}
assert har_parser.hostname == 'humanssuck.net'


def test_match_headers(har_data):
Expand Down