Download site headers
(link: Link, out_dir: Optional[str]=None, timeout: int=TIMEOUT)
| 32 | |
| 33 | @enforce_types |
| 34 | def save_headers(link: Link, out_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult: |
| 35 | """Download site headers""" |
| 36 | |
| 37 | out_dir = Path(out_dir or link.link_dir) |
| 38 | output_folder = out_dir.absolute() |
| 39 | output: ArchiveOutput = 'headers.json' |
| 40 | |
| 41 | status = 'succeeded' |
| 42 | timer = TimedProgress(timeout, prefix=' ') |
| 43 | |
| 44 | cmd = [ |
| 45 | CURL_BINARY, |
| 46 | *CURL_ARGS, |
| 47 | '--head', |
| 48 | '--max-time', str(timeout), |
| 49 | *(['--user-agent', '{}'.format(CURL_USER_AGENT)] if CURL_USER_AGENT else []), |
| 50 | *([] if CHECK_SSL_VALIDITY else ['--insecure']), |
| 51 | link.url, |
| 52 | ] |
| 53 | try: |
| 54 | json_headers = get_headers(link.url, timeout=timeout) |
| 55 | output_folder.mkdir(exist_ok=True) |
| 56 | atomic_write(str(output_folder / "headers.json"), json_headers) |
| 57 | except (Exception, OSError) as err: |
| 58 | status = 'failed' |
| 59 | output = err |
| 60 | finally: |
| 61 | timer.end() |
| 62 | |
| 63 | return ArchiveResult( |
| 64 | cmd=cmd, |
| 65 | pwd=str(out_dir), |
| 66 | cmd_version=CURL_VERSION, |
| 67 | output=output, |
| 68 | status=status, |
| 69 | **timer.stats, |
| 70 | ) |
nothing calls this directly
no test coverage detected