Add --compression option

* doc/wget.texi: Add --compression documentation.
* src/init.c (cmd_spec_compression): New function.
(commands[]): Add opt.compression.
(defaults): Set default opt.compression value.
* src/main.c (option_data[]): Add struct for --compression.
(print_help, help[]): Add description for --compression.
(main): Add incompatibility checks for --compression.
* src/options.h (struct options): Add compression enum and field.
This commit is contained in:
Tim Schlueter 2017-07-24 22:34:46 -07:00 committed by Tim Rühsen
parent 08ed2a5530
commit b543dfe783
4 changed files with 83 additions and 0 deletions

View File

@ -1535,6 +1535,20 @@ wget --header="Host: foo.bar" http://localhost/
In versions of Wget prior to 1.10 such use of @samp{--header} caused
sending of duplicate headers.
@cindex Content-Encoding, choose
@item --compression=@var{type}
Choose the type of compression to be used. Legal values are
@samp{auto}, @samp{gzip} and @samp{none}.
If @samp{auto} or @samp{gzip} are specified, Wget asks the server to
compress the file using the gzip compression format. If the server
compresses the file and responds with the @code{Content-Encoding}
header field set appropriately, the file will be decompressed
automatically. This is the default.
If @samp{none} is specified, wget will not ask the server to compress
the file and will not decompress any server responses.
@cindex redirect
@item --max-redirect=@var{number}
Specifies the maximum number of redirections to follow for a resource.
@ -3368,6 +3382,11 @@ Turn globbing on/off---the same as @samp{--glob} and @samp{--no-glob}.
Define a header for HTTP downloads, like using
@samp{--header=@var{string}}.
@item compression = @var{string}
Choose the compression type to be used. Legal values are @samp{auto}
(the default), @samp{gzip}, and @samp{none}. The same as
@samp{--compression=@var{string}}.
@item adjust_extension = on/off
Add a @samp{.html} extension to @samp{text/html} or
@samp{application/xhtml+xml} files that lack one, a @samp{.css}

View File

@ -99,6 +99,9 @@ CMD_DECLARE (cmd_vector);
CMD_DECLARE (cmd_use_askpass);
#ifdef HAVE_LIBZ
CMD_DECLARE (cmd_spec_compression);
#endif
CMD_DECLARE (cmd_spec_dirstruct);
CMD_DECLARE (cmd_spec_header);
CMD_DECLARE (cmd_spec_warc_header);
@ -161,6 +164,9 @@ static const struct {
{ "checkcertificate", &opt.check_cert, cmd_check_cert },
#endif
{ "chooseconfig", &opt.choose_config, cmd_file },
#ifdef HAVE_LIBZ
{ "compression", &opt.compression, cmd_spec_compression },
#endif
{ "connecttimeout", &opt.connect_timeout, cmd_time },
{ "contentdisposition", &opt.content_disposition, cmd_boolean },
{ "contentonerror", &opt.content_on_error, cmd_boolean },
@ -445,6 +451,10 @@ defaults (void)
opt.ftps_clear_data_connection = false;
#endif
#ifdef HAVE_LIBZ
opt.compression = compression_auto;
#endif
/* The default for file name restriction defaults to the OS type. */
#if defined(WINDOWS) || defined(MSDOS) || defined(__CYGWIN__)
opt.restrict_files_os = restrict_windows;
@ -1445,6 +1455,25 @@ cmd_cert_type (const char *com, const char *val, void *place)
static bool check_user_specified_header (const char *);
#ifdef HAVE_LIBZ
static bool
cmd_spec_compression (const char *com, const char *val, void *place)
{
static const struct decode_item choices[] = {
{ "auto", compression_auto },
{ "gzip", compression_gzip },
{ "none", compression_none },
};
int ok = decode_string (val, choices, countof (choices), place);
if (!ok)
{
fprintf (stderr, _("%s: %s: Invalid value %s.\n"), exec_name, com,
quote (val));
}
return ok;
}
#endif
static bool
cmd_spec_dirstruct (const char *com, const char *val, void *place_ignored _GL_UNUSED)
{

View File

@ -275,6 +275,9 @@ static struct cmdline_option option_data[] =
{ IF_SSL ("certificate-type"), 0, OPT_VALUE, "certificatetype", -1 },
{ IF_SSL ("check-certificate"), 0, OPT_BOOLEAN, "checkcertificate", -1 },
{ "clobber", 0, OPT__CLOBBER, NULL, optional_argument },
#ifdef HAVE_LIBZ
{ "compression", 0, OPT_VALUE, "compression", -1 },
#endif
{ "config", 0, OPT_VALUE, "chooseconfig", -1 },
{ "connect-timeout", 0, OPT_VALUE, "connecttimeout", -1 },
{ "continue", 'c', OPT_BOOLEAN, "continue", -1 },
@ -763,6 +766,10 @@ HTTP options:\n"),
--ignore-length ignore 'Content-Length' header field\n"),
N_("\
--header=STRING insert STRING among the headers\n"),
#ifdef HAVE_LIBZ
N_("\
--compression=TYPE choose compression, one of auto, gzip and none\n"),
#endif
N_("\
--max-redirect maximum redirections allowed per page\n"),
N_("\
@ -1675,6 +1682,26 @@ for details.\n\n"));
}
}
#ifdef HAVE_LIBZ
if (opt.always_rest || opt.start_pos >= 0)
{
if (opt.compression == compression_auto)
{
/* Compression does not work with --continue or --start-pos.
Since compression was not explicitly set, it will be disabled. */
opt.compression = compression_none;
}
else if (opt.compression != compression_none)
{
fprintf (stderr,
_("Compression does not work with --continue or"
" --start-pos, they will be disabled.\n"));
opt.always_rest = false;
opt.start_pos = -1;
}
}
#endif
if (opt.ask_passwd && opt.passwd)
{
fprintf (stderr,

View File

@ -326,6 +326,14 @@ struct options
name. */
bool report_bps; /*Output bandwidth in bits format*/
#ifdef HAVE_LIBZ
enum compression_options {
compression_auto,
compression_gzip,
compression_none
} compression; /* type of HTTP compression to use */
#endif
char *rejected_log; /* The file to log rejected URLS to. */
#ifdef HAVE_HSTS