1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[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.
This commit is contained in:
Witold Filipczyk 2024-10-28 19:14:14 +01:00
parent 13b4998935
commit 271984b760
2 changed files with 30 additions and 5 deletions

View File

@ -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,

View File

@ -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) {