def _download_http_url(link, session, temp_dir):
target_url = link.url.split('<STR_LIT:#>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>resp = session.get(<EOL>target_url,<EOL>headers={"<STR_LIT>": "<STR_LIT>"},<EOL>stream=True,<EOL>)<EOL>resp.raise_for_status()<EOL><DEDENT>except requests.HTTPError as exc:<EOL><INDENT>logger.critical(<EOL>"<STR_LIT>", exc.response.status_code, link,<EOL>)<EOL>raise<EOL><DEDENT>content_type = resp.headers.get('<STR_LIT>', '<STR_LIT>')<EOL>filename = link.filename  <EOL>content_disposition = resp.headers.get('<STR_LIT>')<EOL>if content_disposition:<EOL><INDENT>type, params = cgi.parse_header(content_disposition)<EOL>filename = params.get('<STR_LIT:filename>') or filename<EOL><DEDENT>ext = splitext(filename)[<NUM_LIT:1>]<EOL>if not ext:<EOL><INDENT>ext = mimetypes.guess_extension(content_type)<EOL>if ext:<EOL><INDENT>filename += ext<EOL><DEDENT><DEDENT>if not ext and link.url != resp.url:<EOL><INDENT>ext = os.path.splitext(resp.url)[<NUM_LIT:1>]<EOL>if ext:<EOL><INDENT>filename += ext<EOL><DEDENT><DEDENT>file_path = os.path.join(temp_dir, filename)<EOL>with open(file_path, '<STR_LIT:wb>') as content_file:<EOL><INDENT>_download_url(resp, link, content_file)<EOL><DEDENT>return file_path, content_type<EOL>
Download link url into temp_dir using provided session