From 6c922418543ec6529786b3b798b89a879034f575 Mon Sep 17 00:00:00 2001 From: Tim Schlueter Date: Mon, 24 Jul 2017 22:34:46 -0700 Subject: [PATCH 2/3] 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. --- doc/wget.texi | 19 +++++++++++++++++++ src/init.c | 29 +++++++++++++++++++++++++++++ src/main.c | 27 +++++++++++++++++++++++++++ src/options.h | 8 ++++++++ 4 files changed, 83 insertions(+) diff --git a/doc/wget.texi b/doc/wget.texi index e582d4f..daf70a9 100644 --- a/doc/wget.texi +++ b/doc/wget.texi @@ -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. address@hidden Content-Encoding, choose address@hidden address@hidden +Choose the type of compression to be used. Legal values are address@hidden, @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 address@hidden 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 @address@hidden address@hidden 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 address@hidden@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} diff --git a/src/init.c b/src/init.c index 5f4eefa..1064883 100644 --- a/src/init.c +++ b/src/init.c @@ -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) { diff --git a/src/main.c b/src/main.c index 297499e..f9759c3 100644 --- a/src/main.c +++ b/src/main.c @@ -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, diff --git a/src/options.h b/src/options.h index 3972945..cf945c1 100644 --- a/src/options.h +++ b/src/options.h @@ -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 -- 2.7.4