# HG changeset patch # User neko259 # Date 2016-10-20 10:11:47 # Node ID 0b52d25186ec8a936a16c43711b3db42a28deb27 # Parent 5dc25766f37c1608125ce62bee37b8c49db6ab3e Download HTML only as a link, not as a file diff --git a/boards/models/attachment/downloaders.py b/boards/models/attachment/downloaders.py --- a/boards/models/attachment/downloaders.py +++ b/boards/models/attachment/downloaders.py @@ -19,6 +19,11 @@ FILE_DOWNLOAD_CHUNK_BYTES = 200000 YOUTUBE_URL = re.compile(r'https?://((www\.)?youtube\.com/watch\?v=|youtu.be/)[-\w]+') +TYPE_URL_ONLY = ( + 'application/xhtml+xml', + 'text/html', +) + class Downloader: @staticmethod @@ -77,3 +82,14 @@ class YouTubeDownloader(Downloader): def handles(url: str) -> bool: return YOUTUBE_URL.match(url) + +class NothingDownloader(Downloader): + @staticmethod + def handles(url: str) -> bool: + response_head = requests.head(url, verify=False) + content_type = response_head.headers[HEADER_CONTENT_TYPE].split(';')[0] + return content_type in TYPE_URL_ONLY + + @staticmethod + def download(url: str): + return None