From 271984b760862fef6041364eb04c0eed0dad272e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 28 Oct 2024 19:14:14 +0100 Subject: [PATCH] [download] Added boolean option document.download.compressed_as_plain Enabled by default. It allow to view compressed files automatically. For example files in /usr/share/doc. --- src/config/options.inc | 6 ++++-- src/session/download.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/config/options.inc b/src/config/options.inc index 0332bf803..3399bb955 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -709,8 +709,6 @@ static union option_info config_options_info[] = { /* Keep options in alphabetical order. */ - - INIT_OPT_TREE("document", N_("Downloading"), "download", OPT_ZERO, N_("Options regarding files downloading and handling.")), @@ -724,6 +722,10 @@ static union option_info config_options_info[] = { N_("Set the timestamp of each downloaded file to the " "timestamp stored on the server.")), + INIT_OPT_BOOL("document.download", N_("Show compressed files as plain text"), + "compressed_as_plain", OPT_ZERO, 1, + N_("Whether to view compressed files (.gz, .zst or .xz) as plain text.")), + /* Does automatic resuming make sense as an option? */ INIT_OPT_INT("document.download", N_("Prevent overwriting"), "overwrite", OPT_ZERO, 0, 2, 2, diff --git a/src/session/download.c b/src/session/download.c index fdf659d20..644c9269e 100644 --- a/src/session/download.c +++ b/src/session/download.c @@ -1913,6 +1913,19 @@ struct { { NULL, 1 }, }; +static const char *compressed_types[] = { +#ifdef CONFIG_GZIP + "application/gzip", +#endif +#ifdef CONFIG_ZSTD + "application/zstd", +#endif +#ifdef CONFIG_LZMA + "application/x-xz", +#endif + NULL +}; + /*! @relates type_query */ int setup_download_handler(struct session *ses, struct download *loading, @@ -1936,12 +1949,22 @@ setup_download_handler(struct session *ses, struct download *loading, plaintext = known_types[i].plain; goto plaintext_follow; } - xwin = ses->tab->term->environment & ENV_XWIN; handler = get_mime_type_handler(ctype, xwin); - if (!handler && strlen(ctype) >= 4 && !c_strncasecmp(ctype, "text", 4)) - goto plaintext_follow; + if (!handler) { + if (strlen(ctype) >= 4 && !c_strncasecmp(ctype, "text", 4)) { + goto plaintext_follow; + } + for (i = 0; compressed_types[i]; i++) { + if (c_strcasecmp(ctype, compressed_types[i])) { + continue; + } + if (get_opt_bool("document.download.compressed_as_plain", ses)) { + goto plaintext_follow; + } + } + } type_query = find_type_query(ses); if (type_query) {