Skip to content

Commit

Permalink
Merge pull request #14 from romanisecke/expand-request-type
Browse files Browse the repository at this point in the history
Allow for requests.get to be used for expansion
  • Loading branch information
mabrownnyu committed Jul 11, 2021
2 parents 6de5ecd + 701a970 commit 05e8eff
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions urlexpander/core/api.py
Expand Up @@ -126,19 +126,23 @@ def _parse_error(error, verbose=False):
return domain, url_endpoint


def _expand(link, timeout=2, verbose=False, **kwargs):
def _expand(link, timeout=2, verbose=False, use_head=True, **kwargs):
'''
Expands a url, while taking into consideration: special link shortener or analytics platforms that either need a sophisticated
redirect(st.sh), or parsing of the url (ln.is)
:param link: string of a link to unshorten.
:returns: a dictionary with the original link, the unshortened link, and the unshortened domain.
'''
if use_head:
http_op = requests.head
else:
http_op = requests.get
try:
r = requests.head(link,
allow_redirects=True,
timeout=timeout,
**kwargs)
r = http_op(link,
allow_redirects=True,
timeout=timeout,
**kwargs)
r.raise_for_status()
url_long = r.url
domain = get_domain(url_long)
Expand Down

0 comments on commit 05e8eff

Please sign in to comment.