Add some logging for content-disposition
This commit is contained in:
parent
0d38e1814e
commit
9585b3c925
@ -33,15 +33,11 @@ import qutebrowser.commands.utils as cmdutils
|
|||||||
import qutebrowser.utils.misc as utils
|
import qutebrowser.utils.misc as utils
|
||||||
from qutebrowser.utils.http import parse_content_disposition
|
from qutebrowser.utils.http import parse_content_disposition
|
||||||
from qutebrowser.utils.log import downloads as logger
|
from qutebrowser.utils.log import downloads as logger
|
||||||
from qutebrowser.utils.log import fix_rfc2622
|
|
||||||
from qutebrowser.utils.usertypes import PromptMode, Question, Timer
|
from qutebrowser.utils.usertypes import PromptMode, Question, Timer
|
||||||
from qutebrowser.utils.qt import qt_ensure_valid
|
from qutebrowser.utils.qt import qt_ensure_valid
|
||||||
from qutebrowser.commands.exceptions import CommandError
|
from qutebrowser.commands.exceptions import CommandError
|
||||||
|
|
||||||
|
|
||||||
fix_rfc2622()
|
|
||||||
|
|
||||||
|
|
||||||
class DownloadItem(QObject):
|
class DownloadItem(QObject):
|
||||||
|
|
||||||
"""A single download currently running.
|
"""A single download currently running.
|
||||||
|
@ -19,13 +19,16 @@
|
|||||||
|
|
||||||
"""pyPEG parsing for the RFC 6266 (Content-Disposition) header. """
|
"""pyPEG parsing for the RFC 6266 (Content-Disposition) header. """
|
||||||
|
|
||||||
import pypeg2 as peg
|
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import string
|
import string
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import pypeg2 as peg
|
||||||
|
|
||||||
|
from qutebrowser.utils.log import rfc6266 as logger
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UniqueNamespace(peg.Namespace):
|
class UniqueNamespace(peg.Namespace):
|
||||||
|
|
||||||
@ -298,6 +301,7 @@ def parse_headers(content_disposition):
|
|||||||
# filename parameter. But it does mean we occasionally give
|
# filename parameter. But it does mean we occasionally give
|
||||||
# less-than-certain values for some legacy senders.
|
# less-than-certain values for some legacy senders.
|
||||||
content_disposition = content_disposition.decode('iso-8859-1')
|
content_disposition = content_disposition.decode('iso-8859-1')
|
||||||
|
logger.debug("Parsing Content-Disposition: {}".format(content_disposition))
|
||||||
# Our parsing is relaxed in these regards:
|
# Our parsing is relaxed in these regards:
|
||||||
# - The grammar allows a final ';' in the header;
|
# - The grammar allows a final ';' in the header;
|
||||||
# - We do LWS-folding, and possibly normalise other broken
|
# - We do LWS-folding, and possibly normalise other broken
|
||||||
@ -305,10 +309,11 @@ def parse_headers(content_disposition):
|
|||||||
# XXX Would prefer to accept only the quoted whitespace
|
# XXX Would prefer to accept only the quoted whitespace
|
||||||
# case, rather than normalising everything.
|
# case, rather than normalising everything.
|
||||||
content_disposition = normalize_ws(content_disposition)
|
content_disposition = normalize_ws(content_disposition)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
parsed = peg.parse(content_disposition, ContentDispositionValue)
|
parsed = peg.parse(content_disposition, ContentDispositionValue)
|
||||||
except (SyntaxError, DuplicateParamError, InvalidISO8859Error):
|
except (SyntaxError, DuplicateParamError, InvalidISO8859Error) as e:
|
||||||
|
logger.warning("Error while parsing Content-Disposition: "
|
||||||
|
"{} - {}".format(e.__class__.__name__, e))
|
||||||
return ContentDisposition()
|
return ContentDisposition()
|
||||||
else:
|
else:
|
||||||
return ContentDisposition(disposition=parsed.dtype,
|
return ContentDisposition(disposition=parsed.dtype,
|
||||||
|
Loading…
Reference in New Issue
Block a user