bug-wget
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-wget] Patch: new option --content-on-error: do not skip content on


From: Henrik Holst
Subject: [Bug-wget] Patch: new option --content-on-error: do not skip content on http server error
Date: Sun, 2 Oct 2011 01:26:00 +0200

This patch adds an option to not skip the content sent by the HTTP server
when the server responds with a status code in the 4xx and 5xx range.

This is quite useful when dealing with RESTful web services since they often
use the http status code to indicate an error and then add content with an
extended explanation of the error in question.
I noticed that cURL by default shows the content on error and has instead an
option to disable it but I guess that changing the default behavior of wget
is kind of out of the question :-)

And besides beeing useful, RFC2616 states that "User agents SHOULD display
any included entity to the user." for client errors (4xx).

I have attached the patch since I know that Gmail sometimes does tricks with
inline patches.

/Henrik Holst

diff -u wget-1.13_orig/src/http.c wget-1.13/src/http.c
--- wget-1.13_orig/src/http.c    2011-10-02 00:59:05.949926929 +0200
+++ wget-1.13/src/http.c    2011-10-01 01:29:52.740942125 +0200
@@ -2448,7 +2448,7 @@
   type = NULL;                        /* We don't need it any more.  */

   /* Return if we have no intention of further downloading.  */
-  if (!(*dt & RETROKF) || head_only)
+  if ((!(*dt & RETROKF) && !opt.content_on_error) || head_only)
     {
       /* In case the caller cares to look...  */
       hs->len = 0;
diff -u wget-1.13_orig/src/init.c wget-1.13/src/init.c
--- wget-1.13_orig/src/init.c    2011-10-02 00:59:05.979926929 +0200
+++ wget-1.13/src/init.c    2011-10-01 01:34:02.810941982 +0200
@@ -139,6 +139,7 @@
   { "chooseconfig",     &opt.choose_config,    cmd_file },
   { "connecttimeout",   &opt.connect_timeout,   cmd_time },
   { "contentdisposition", &opt.content_disposition, cmd_boolean },
+  { "contentonerror",   &opt.content_on_error,  cmd_boolean },
   { "continue",         &opt.always_rest,       cmd_boolean },
   { "convertlinks",     &opt.convert_links,     cmd_boolean },
   { "cookies",          &opt.cookies,           cmd_boolean },
diff -u wget-1.13_orig/src/main.c wget-1.13/src/main.c
--- wget-1.13_orig/src/main.c    2011-10-02 00:59:05.859926929 +0200
+++ wget-1.13/src/main.c    2011-10-01 01:50:05.760941442 +0200
@@ -178,6 +178,7 @@
     { "continue", 'c', OPT_BOOLEAN, "continue", -1 },
     { "convert-links", 'k', OPT_BOOLEAN, "convertlinks", -1 },
     { "content-disposition", 0, OPT_BOOLEAN, "contentdisposition", -1 },
+    { "content-on-error", 0, OPT_BOOLEAN, "contentonerror", -1 },
     { "cookies", 0, OPT_BOOLEAN, "cookies", -1 },
     { "cut-dirs", 0, OPT_VALUE, "cutdirs", -1 },
     { WHEN_DEBUG ("debug"), 'd', OPT_BOOLEAN, "debug", -1 },
@@ -595,6 +596,8 @@
        --content-disposition   honor the Content-Disposition header when\n\
                                choosing local file names
(EXPERIMENTAL).\n"),
     N_("\
+       --content-on-error      output the received content on server
errors.\n"),
+    N_("\
        --auth-no-challenge     send Basic HTTP authentication
information\n\
                                without first waiting for the server's\n\
                                challenge.\n"),
diff -u wget-1.13_orig/src/options.h wget-1.13/src/options.h
--- wget-1.13_orig/src/options.h    2011-10-02 00:59:05.949926929 +0200
+++ wget-1.13/src/options.h    2011-10-01 01:46:34.520941561 +0200
@@ -130,6 +130,8 @@
   bool server_response;        /* Do we print server response? */
   bool save_headers;        /* Do we save headers together with
                    file? */
+  bool content_on_error;    /* Do we output the content when the HTTP
+                   status code indicates a server error */

 #ifdef ENABLE_DEBUG
   bool debug;            /* Debugging on/off */
diff -u wget-1.13_orig/doc/wget.info wget-1.13/doc/wget.info
--- wget-1.13_orig/doc/wget.info    2011-10-02 00:59:06.769926929 +0200
+++ wget-1.13/doc/wget.info    2011-10-02 00:58:26.139926946 +0200
@@ -1288,6 +1288,10 @@
      use `Content-Disposition' headers to describe what the name of a
      downloaded file should be.

+`--content-on-error'
+     If this is set to on, wget will not skip the content when the
+     server responds with a http status code that indicates error.
+
 `--trust-server-names'
      If this is set to on, on a redirect the last component of the
      redirection URL will be used as the local file name.  By default
diff -u wget-1.13_orig/doc/wget.texi wget-1.13/doc/wget.texi
--- wget-1.13_orig/doc/wget.texi    2011-10-02 00:59:06.769926929 +0200
+++ wget-1.13/doc/wget.texi    2011-10-02 00:58:21.869926947 +0200
@@ -1506,6 +1506,12 @@
 @code{Content-Disposition} headers to describe what the name of a
 downloaded file should be.

address@hidden Content On Error
address@hidden --content-on-error
+
+If this is set to on, wget will not skip the content when the server
responds
+with a http status code that indicates error.
+
 @cindex Trust server names
 @item --trust-server-names

Attachment: wget.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]