Skip to content

Commit

Permalink
Switch validation to HEAD requests for YouTube support
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Apr 22, 2016
1 parent 8f2ad48 commit e15fa29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions memegen/domain/template.py
Expand Up @@ -175,7 +175,7 @@ def validate_link(self):
else:
log.info("Checking link %s ...", self.link)
try:
response = requests.get(self.link, timeout=5)
response = requests.head(self.link, timeout=5)
except requests.exceptions.ReadTimeout:
log.warning("Connection timed out")
return True # assume URL is OK; it will be checked again
Expand All @@ -185,7 +185,7 @@ def validate_link(self):
self._error("link is invalid (%s)", response.status_code)
return False
else:
with open(flag, 'w') as stream:
with open(str(flag), 'w') as stream:
stream.write(str(int(time.time())))
return True

Expand Down
2 changes: 1 addition & 1 deletion memegen/test/test_domain_template.py
Expand Up @@ -136,7 +136,7 @@ def with_bad_link(template):
mock_response = Mock()
mock_response.status_code = 404

with patch('requests.get', Mock(return_value=mock_response)):
with patch('requests.head', Mock(return_value=mock_response)):
template.link = "example.com/fake"

expect(template.validate_link()) == False
Expand Down

0 comments on commit e15fa29

Please sign in to comment.